pouncer Posted November 8, 2006 Share Posted November 8, 2006 [code=php:0] session_register('UserID'); session_register('Username'); session_register('Email'); session_register('User_Level'); $_SESSION['UserID'] = $row['userid']; $_SESSION['Username'] = $Username; $_SESSION['Email'] = $row['email_address']; $_SESSION['User_Level'] = $row['user_level'];[/code]I'm not sure if I need the session_register stuff?Also, as soon as the session variables are set after a user logs in successfully, will these variables be for all pages? so at the top of every php page do i simply putsession_start();one of my pages is member.php - i need to check if the member is logged in, for this page to be viewable by a member. how could i do this? is this a correct way?[code=php:0]if isset($_SESSION['Username']) && ($_SESSION['UserID'] == 0) echo "Logged in as member";else {echo "You are not logged in";//redirect back to index.html}[/code]for the admin.php the userid must be 1. similar type of code here?am i in the right direction guys? Link to comment https://forums.phpfreaks.com/topic/26550-sessions/ Share on other sites More sharing options...
onlyican Posted November 8, 2006 Share Posted November 8, 2006 startersthe old way of creating sessions is session_register()but I have noticed bugs in that, and it is now suggested to use$_SESSION["name"] = "VALUE";Secondsession_start(); needs to be on the top of every pageBEFORE htm codeThirdto check if sessions are present, you can do something like if((isset($_SESSION["username"])) && (isset($_SESSION["UserID"]))){(The extra brackets mean this condition, AND that condition, not ONE condition Link to comment https://forums.phpfreaks.com/topic/26550-sessions/#findComment-121461 Share on other sites More sharing options...
pouncer Posted November 8, 2006 Author Share Posted November 8, 2006 Thanks for the info.Much appreciated. Link to comment https://forums.phpfreaks.com/topic/26550-sessions/#findComment-121486 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.