Jump to content

PHP isset session check


ncurran217

Recommended Posts

I have worked up a login page and everything and works great, as well as on all the other pages set to if not logged in it will redirect to the login page. Code is here:

 

<?php
session_start();
if (!(isset($_SESSION['forteid']) && $_SESSION['forteid'] != '')) {
header ("Location: login.php");
}
?>

 

Now trying to add in certain pages where only certain access can access the page if not it will redirect back to the home page. This is what I have, but when not logged in and go to a page with this at the top, it just seems to skip over the first if (!isset) check:

 

<?php
session_start();
if (!(isset($_SESSION['forteid']) && $_SESSION['forteid'] != '')) {
header ("Location: login.php");
}
if (!(isset($_SESSION['accesslevel']) && $_SESSION['accesslevel'] != '1')) {
header ("Location: noaccess.php");
}
?>

 

I thought if else statement but not sure how to write that. Thanks for the help in advance!

Link to comment
Share on other sites

Using header() to redirect will not stop your script. It will keep on running. If that second condition also happened to match then the redirect to login.php will be overwritten with noaccess.php.

 

Always exit; right after you send the header().

 

[edit] Also, does your logout process trash the entire session or just the forteid? It should get rid of everything.

Edited by requinix
Link to comment
Share on other sites

Using header() to redirect will not stop your script. It will keep on running. If that second condition also happened to match then the redirect to login.php will be overwritten with noaccess.php.

 

Always exit; right after you send the header().

 

[edit] Also, does your logout process trash the entire session or just the forteid? It should get rid of everything.

 

This is what I have for my logout.php page:

 

<?php
session_start();
session_destroy();
header("location: login.php");
exit()
?>

 

Is that good? Or do you recommend something else?

Edited by ncurran217
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.