Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9
This is the forum to discuss the Wrox book PHP and MySQL: Create-Modify-Reuse by Timothy Boronczyk, Martin E. Psinas; ISBN: 9780470192429
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 11th, 2011, 06:57 PM
Authorized User
 
Join Date: Apr 2011
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Default Please help with chapter 10

Hi,

I have successfully gotten the user creation/login and the forums to work, but I have a few issues.

1)how do I automatically update user permissions so that they can post in the forums, and delete their own posts, but not create new forums? (I am fine with automatically changing permissions for admins in ch 10)

2)when I go to admin.php and try to post, I am directed to a completely blank screen. also, it seems that I can access the admin.php page with any logged in username, how would I make this so that only one or two accounts can access that page?

any help would be greatly appreciated, this forum has been a major help thus far.
thanks!!
Reply With Quote
  #2 (permalink)  
Old June 12th, 2011, 02:57 PM
Authorized User
Points: 374, Level: 6
Points: 374, Level: 6 Points: 374, Level: 6 Points: 374, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: San Jose, Californina
Posts: 77
Thanks: 4
Thanked 6 Times in 6 Posts
Default

Hi ninjask,

In Chapter 2, User.php, lines 5-8, there are some
constants defined which are used in permissions.
PHP Code:
const CREATE_FORUM 2;
const 
MOVE_MESSAGE 4;
const 
DELETE_MESSAGE 8;
const 
DELETE_FORUM 16
Permission checking is done by comparing
$user->permission to these constants.
For example this line does a bitwise
comparison to see if a user has permission
to create a forum.
PHP Code:
  if ($user->permission User::CREATE_FORUM
If you want a user to be able to move and delete messages, but
not create or delete forums you could give them a permission
like this:
PHP Code:
$user->permission User::DELETE_MESSAGE User::MOVE_MESSAGE
The author discusses permissions and bitwise operators on
page 33.

You could create additional constants for different kinds of
permissions and assign any combination of permissions you want
to a user.

There are different ways to add permissions to a user.
One way is to set user permissions directly into the database.
Another way is to modify the examples in the book to assign
permissions to a user. Perhaps you could assign permission
based on something you have the user enter on registration
such as a membership level or something like that.

There is a problem with ~$user->permission in add_forum.php

Chap 2, add_forum.php, ~$user->permission is not working properly


2) Your second question

What you want is an enhanced version of a 401.php file
that can limit access to 1 or 2 users.
We cannot alter 401.php because we use it many places, but
what you can do is create a new file, let's say 401check.php
The way you create this file is to copy 401.php to 401check.php.
Then at the bottom of this new file add additional checks to
allow only the users you want. Then in admin10.php include
401check.php instead of 401.php.

The additional checks in 401check.php can be done with an additional
if statement at the end. Here is an example..

PHP Code:
 $theuser = "me";
 if ( $_SESSION['username'] != $theuser ) {
    
    define('EMAIL_ADDRESS_TO_SEND', 'myemail@emailprovider.com');
    $msg = "Someone tried to get into  admin10.php. " .  "Their username is " . 
 $_SESSION['username'];
 
    mail(EMAIL_ADDRESS_TO_SEND, "My web site, someone tried to get in ", $
 msg);
 ?>
 <p>The resource you've requested is for my web site use. Either you have
 not supplied the necessary credentials or the credentials you have supplied
 do not authorize you for access.</p>
 <a href="../index.php">return to main page</a>
 
 <?php
    $GLOBALS
['TEMPLATE']['content'] = ob_get_clean();
 
    include 
'../templates/template-page.php';
    exit();
 }

 
?>
There are some posts in this forum regarding chapter 10. They were entered
in October 2010. You may want to look at those.
Reply With Quote
  #3 (permalink)  
Old June 21st, 2011, 03:23 AM
Authorized User
 
Join Date: Apr 2011
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Huge help! thanks a ton!

I think I'm starting to get the hang of it.. :P
Reply With Quote
  #4 (permalink)  
Old June 23rd, 2011, 04:38 AM
Authorized User
 
Join Date: Apr 2011
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Default re: chapter 10

Thank you for your response, you have helped me clear up the majority of my issues, however I still have one problem that I am unable to solve. I have checked all the other forums throughly and there doesnt seem to be a similar problem for this chapter.

When I go to admin.php, the popup list for "select or add new" comes up.
I select add new, and still no problem, the form for entering the post shows up.

but after I fill out the post and hit "submit" , I am directed to "post_admin.php"
this screen is ALWAYS blank! nothin. no way to confirm that I want to post, and no posts to see.

I tried referencing the template_page.php but it didnt make a difference.

I'm at the end of my rope!
Reply With Quote
  #5 (permalink)  
Old June 23rd, 2011, 11:54 PM
Authorized User
Points: 374, Level: 6
Points: 374, Level: 6 Points: 374, Level: 6 Points: 374, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2009
Location: San Jose, Californina
Posts: 77
Thanks: 4
Thanked 6 Times in 6 Posts
Default

Hi Ninjask,

post_admin.php does not show anything, it just writes to
the database and redirects you back to admin.php
This happens very quickly. You should not being seeing
post_admin.php in your browser address bar. If you do,
then something is wrong in your post_admin.php file.
At the bottom of post_admin.php file is a line like
PHP Code:
      header('Location: admin.php'); 
If this is missing or commented out, you will get a blank
page, and see post_admin.php in your browser address bar.
If you do have this line and the wrong file is specified
your page will say "No input file specified"
Try debugging that file and make sure you are getting to
this line. Also, check your database and make sure you post is
getting written.

I hope this helps.
Reply With Quote
  #6 (permalink)  
Old June 24th, 2011, 02:19 AM
Registered User
 
Join Date: Jun 2011
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Everyone
I'm new to This forum
it is great to join this Forum, hope i'm welcome in ;) http://freeimagestocks.com/content/69/grey.png
Reply With Quote
The Following User Says Thank You to deeanabrown7 For This Useful Post:
RacerBoy (September 2nd, 2015)
  #7 (permalink)  
Old June 25th, 2011, 04:08 AM
Authorized User
 
Join Date: Apr 2011
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Default

haha thanks again, friend!
Reply With Quote
  #8 (permalink)  
Old August 20th, 2015, 08:46 AM
Authorized User
Points: 59, Level: 1
Points: 59, Level: 1 Points: 59, Level: 1 Points: 59, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 12
Thanks: 0
Thanked 2 Times in 2 Posts
Default ch10 admin.php

I am having problems with posting articles to the blog. When I submit the screen goes blank and in the browser address bar you see post_admin.php. The header at the bottom of post_admin.php is correctly specified referring back to admin.php. No files are uploaded to the database. Can anyone give me some ideas where to look? Thanks
Reply With Quote
The Following User Says Thank You to Albion For This Useful Post:
RacerBoy (September 2nd, 2015)
  #9 (permalink)  
Old August 28th, 2015, 03:14 PM
Authorized User
Points: 59, Level: 1
Points: 59, Level: 1 Points: 59, Level: 1 Points: 59, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 12
Thanks: 0
Thanked 2 Times in 2 Posts
Default Chapter ten post-admin

Everything sorted, thanks.
Reply With Quote
  #10 (permalink)  
Old September 2nd, 2015, 11:38 AM
Authorized User
Points: 146, Level: 2
Points: 146, Level: 2 Points: 146, Level: 2 Points: 146, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2015
Location: Dhaka, Bangladesh
Posts: 39
Thanks: 3
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by Albion View Post
I am having problems with posting articles to the blog. When I submit the screen goes blank and in the browser address bar you see post_admin.php. The header at the bottom of post_admin.php is correctly specified referring back to admin.php. No files are uploaded to the database. Can anyone give me some ideas where to look? Thanks
I think you should leave from now and come back again then try.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 10 thepianoguy BOOK: Professional iPhone and iPad Application Development 1 March 31st, 2011 11:29 AM
Chapter 10, listing 10-10-app kiwibrit BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 2 August 18th, 2009 04:21 AM
Chapter 10 czambran BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 March 29th, 2005 08:35 AM
Chapter 10 columbiasmiles JSP Basics 0 May 17th, 2004 08:09 PM



All times are GMT -4. The time now is 12:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.