Reputation: 3620
i want to redirect login.php to index.php when $_SESSION['user'] is not empty (user logged in)
<?php
session_start();
if (isset($_SESSION['user'])){
header ('refresh:3 ; URL:index.php');
}
?>
but when user log in the page doesn't redirect to the index.php
Upvotes: 0
Views: 1429
Reputation: 4458
You're doing it wrong. Example of how to do it and some more info about the header.
<?php
session_start ();
if (isset($_SESSION['user'])
{
header ('Refresh: 3; url=index.php');
// ^
}
?>
You used :
it should be an equal sign.
Upvotes: 1
Reputation: 2204
This should work:
<?php
session_start();
if (isset($_SESSION['user'])){
header('Location: http://www.yoursite.com/');
die();
}
?>
If you want to redirect the user after x senconds, then use
<?php
session_start();
if (isset($_SESSION['user'])){
header( "refresh:3;url=whatever.php" );
}
?>
Upvotes: 5