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 Link to comment https://forums.phpfreaks.com/topic/100851-help-with-sessions/ 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")) Link to comment https://forums.phpfreaks.com/topic/100851-help-with-sessions/#findComment-515726 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 Link to comment https://forums.phpfreaks.com/topic/100851-help-with-sessions/#findComment-515730 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? Link to comment https://forums.phpfreaks.com/topic/100851-help-with-sessions/#findComment-515731 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. Link to comment https://forums.phpfreaks.com/topic/100851-help-with-sessions/#findComment-515734 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(); } ?> Link to comment https://forums.phpfreaks.com/topic/100851-help-with-sessions/#findComment-515762 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.