Reputation: 6292
Basically I will tell you what I want to do.
1: If a user is not logged in I want them to be re-directed back to the login page.
2: If a user is Logged in and they submitted a form I want them to be directed to the next page.
I have tried it with meta refresh but I can only seem to get it working with one or the other.
Can you please advise what the best way to do this would be ?
the code I am using at the moment is
<meta http-equiv="refresh" content="0;index.php">
<meta http-equiv="refresh" name="myidentifier" content="0;mystats.php">
Thanks
Upvotes: 0
Views: 116
Reputation: 8826
Use http headers instead. For example:
session_start();
//Redirect when user is not logged
if($_SESSION['logged'] != 1)
{
header("Location: http://redirect.here.com/login.php");
exit(0);
}
//Redirect when user sent form
if((isset($_POST['sent']))&&($_SESSION['logged']==1))
{
header("Location: http://redirect.here.com/nextpage.php");
exit(0);
}
Don't forget to set $_SESSION['logged']=1
after successful login.
There are more methods of detecting that user sent form, but I prefer placing hidden input field with name="sent"
to each form.
Upvotes: 5