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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.