
December 17th, 2006, 01:00 AM
|
|
|
|
Join Date: Apr 2007
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
RE: let user access to user own pages
I found this simple to do when just making one. I havnt used anything tricky at all.
just have a form to login wich passes the username and the password to another page that runs the sql called login.php wich amongst other stuff contains this
php Code:
Original
- php Code |
|
|
|
$connection = mysql_connect($hostname, $username, $password) or die ("Unable to connect!"); $query = "SELECT uid, uperms from users WHERE uuser = '$uuser' AND upass = '$upass'"; // if row exists - login/pass is correct { // initiate a session // register the user's ID and permission level $SESSION_UID = $uid; $SESSION_UPERMS = $uperms; // redirect to main menu page header("Location:testingpass.php"); // close connection } else // login/pass check failed { // redirect to error page } ?>
this is then dealt with by testingpass.php which includes the users index page as an isclude for each level of users as follows
php Code:
Original
- php Code |
|
|
|
your unique user id is <?php echo $SESSION_UID ?> <br> your permission level is set to <?php echo $SESSION_UPERMS ?> <br> <?php // decide if user is admin or a lower level to bring up their relevant index page ?> <?php if ($SESSION_UPERMS == "1") { echo "your an admin so you get full acccess to all pages" ; } else { echo "your a Normal user of the system so you get a customised links page with only the info you need on it depending on your users permission level!" ; } ?> <? //php elseif for showing the subadmins pages ?> <? if( $SESSION_UPERMS == "1" ) { include ("level1.php"); } elseif( $SESSION_UPERMS == "2" ) { include ("level2.php"); } elseif( $SESSION_UPERMS == "3" ) { include ("level3.php"); } elseif( $SESSION_UPERMS == "4" ) { include ("level4.php"); } elseif( $SESSION_UPERMS == "5" ) { include ("level5.php"); }
then at the top of level1.php i have the following lines
php Code:
Original
- php Code |
|
|
|
<? // check for valid user session { $SESSION_UPERMS != 1; } $SESSION_UPERMS = 1; ?>
This should hopefully stop direct access to the pages bypassing the security login feature by bookmarks and stuff.
I would like any feedback as its my first attempt at thsi sort of stuff.
|