Jump to content

[SOLVED] Simple Session Question


chocopi

Recommended Posts

  • Firstly, once you have started and registered the sesssion when you change page does the session continue or do you have to call it?
     

  • Secondly, how can you check if the session has been started and if its false then they are redirected to the login (to stop users from going to pages without logging in)

 

Thanks,

 

~ Chocopi

Link to comment
https://forums.phpfreaks.com/topic/52241-solved-simple-session-question/
Share on other sites

You don't register sessions, if your talking about session_register() it has long been depricated.

 

Sessions are passed from page to page but each page needs a call to session_start(). To check a session variable has been set, use something like....

 

<?php

  session_start();
  if (!isset($_SESSION['logged'])) {
    // user is NOT logged in.
  }

?>

ok thanks, just out of intrest could you replace the 'logged' past with user id which is taken from the database

 

Yeah... you can replace it with whatever you think you'll need to follow a user around with. for a login system, I usually use a few variables. Something like...

 

$_SESSION['logged'] = true;
$_SESSION['uname'] = $row['uname']
$_SESSION['perms'] = $row['perms']

 

Where $row is the users record pulled from the database upon login varification.

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.