abch624 Posted June 29, 2008 Share Posted June 29, 2008 Hi Guys, I want to put an if statement on all pages that should not be viewed if the user is not logged in. I use this if (empty($_SESSION['accountDetailsID']) || empty($_SESSION['email'])) { Header("Location:index.php"); exit; } On my login page I have a create session part that is like this // Register $email, $mypassword and redirect to file "viewprofile.php" session_start(); session_register("email"); session_register("mypassword"); $_SESSION['accountDetailsID']=$accountDetailsID; $_SESSION['email']=$email; header("location:viewprofile.php"); die(); } Now what happens is: Even though I am logged in I can not navigate to the viewprofile.php and it just redirects me back to index.php page Please help - Thanks Quote Link to comment Share on other sites More sharing options...
webent Posted June 29, 2008 Share Posted June 29, 2008 Try... session_start(); $_SESSION['accountDetailsID']='$accountDetailsID'; $_SESSION['email']='$email'; header("location:viewprofile.php"); Quote Link to comment Share on other sites More sharing options...
phpSensei Posted June 29, 2008 Share Posted June 29, 2008 First, please echo both sessions to see if they truly are empty. Also make sure when you register the sessions the values given to them are not empty. Make sure you are using session_start for all pages that require sessions validation. Also, why is there a bracket at the end of the 2nd script, it tells me there is an if statement, if so please post the entire script. thanks. edit: Replace empty with if(isset($_SESSION['accountDetailsID'])){ Quote Link to comment Share on other sites More sharing options...
abch624 Posted June 29, 2008 Author Share Posted June 29, 2008 Hi, This now works. The problem was this: I had written the if statement if (empty($_SESSION['accountDetailsID']) || empty($_SESSION['email'])) { Header("Location:index.php"); exit; } before the session start statement. But now it is like this session_start(); if (empty($_SESSION['accountDetailsID']) || empty($_SESSION['email'])) { Header("Location:index.php"); exit; } All works and ya you spoted it right there was an if statement. Cheers - Zahid 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.