steviez Posted April 12, 2008 Share Posted April 12, 2008 Hi, I am having some strange problems with sessions in my script. When a user logs in my script sets the sessions as follows: session_start(); $_SESSION['loggedin'] = 1; And then on member only pages i use this code to check if they are logged in: session_start(); if(!isset($_COOKIE['loggedin']) && $_COOKIE['loggedin'] == md5("TRUE")) { header("location: $secure_url/login.php"); exit(); } But it always redirects the users to the login page, but if i echo the session i get the value. Any ideas? Thanks But Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 12, 2008 Share Posted April 12, 2008 try maybe changing from if(!isset($_COOKIE['loggedin']) && $_COOKIE['loggedin'] == md5("TRUE")) to if(!isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == md5("TRUE")) Quote Link to comment Share on other sites More sharing options...
steviez Posted April 12, 2008 Author Share Posted April 12, 2008 sorry, i already have done that... it was just an example from my code. Its strange why it wont work. Im using php 5 Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted April 12, 2008 Share Posted April 12, 2008 have you also troubleshooted the $_SESSIONs? just trying to echoing out the value of them and see if it's printing out the expected result? Quote Link to comment Share on other sites More sharing options...
steviez Posted April 12, 2008 Author Share Posted April 12, 2008 link=topic=192273.msg863757#msg863757 date=1208036971] have you also troubleshooted the $_SESSIONs? just trying to echoing out the value of them and see if it's printing out the expected result? I have done that and i am getting the exact result that i want. Its only when i try to check if its set. Quote Link to comment Share on other sites More sharing options...
ikmyer Posted April 12, 2008 Share Posted April 12, 2008 pretty sure you would have to use the $_SESSION['loggedin'] and maybe try... <?php session_start(); if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == 1) { // ok } else { header("location: $secure_url/login.php"); exit(); } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.