Reputation: 135
I have: header.php, register.php, login.php and profile.php
When the user is login in, I redirect him on profile.php using header(Location:profile.php)
Also, before I do that redirect I set a session:
$_SESSION['logged']= $user_email;
Using that, I would like to do a small trick on header.php, something like:
if(($_SESSION['logged'] == true) {
echo "<a href="profile.php"> Logo </a>";
}
else {
echo "<a href="index.php"> Logo </a>";
}
Somehow, this isn't working. I'm missing something?
Upvotes: 1
Views: 3020
Reputation: 176
You can control session variable with isset() function
Try code below
session_start();
if(isset($_SESSION['logged'])){
header("location:profile.php");
}
else{
header("location:index.php");
}
Upvotes: 3