Jump to content

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.

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.