Hello there, I have been busy building a login system lately, and now everything but 1 thing works. So when you are logged in you should be redirected to home.php, and when you are not logged in you should be redirected to index.php, so i came with this bit of code: <?php session_start(); if($_SESSION["login_user"] = true) { ?> //html goes in here <?php } else { header("location: /index.php"); } ?> PHP: but i wouldnt have come here if this worked. Here is the problem: it throws the system into an infinite loop, until chrome terminates it... so i made a logout.php to end any session that may be there (at least i think) <?php session_start(); session_destroy(); ?> PHP: Doesnt fix anything... So, could somebody check these 2 items out, and tell me what i am doing wrong? (if anybody needs it: not logged in homepage: /index.php logged in homepage: /home.php logout page: /logout.php login code: /login.php thankyou in advance!
You're not checking the $_SESSION['login_user'], you're assigning it. Change the first line to: if ($_SESSION['login_user'] == true) { Code (markup):
On top: if ( !isset($_SESSION["login_user"] ) { header("location: /index.php"); } ........... then here is the script more elegant! )