Jump to content

sessions


pouncer

Recommended Posts

[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 put

session_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

starters
the 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";

Second
session_start(); needs to be on the top of every page
BEFORE htm code

Third
to 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.