My server running in PHP 5.2.9, When I using refresh and header functions it's not working. Here is my code
header("location: index.php");
header( "Refresh: 0;" );
Previously I'm working in a different server, It's working correctly. How can I solve this problem?
this is my complete code
if($_POST['sign_in'])
{
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "SELECT * FROM tbl_members WHERE m_email='$email' and m_password='$password'";
$res = mysql_query($sql);
$count = mysql_num_rows($res);
if($count==1)
{
session_register("email");
header("location: index.php");
}
else
{
$sql = "SELECT * FROM tbl_temp_members WHERE email='$email'";
$res = mysql_query($sql);
$count = mysql_num_rows($res);
if($count==1)
{
echo "Login unsuccessful,Account still not activated";
}
else
{
echo "Login unsccessful";
}
}
}
Location and Refresh both require an absolute URI (and it's "Location" instead of "location").
Try this one:
header('Location: http://absolute.uri/file.ext');
If that does not help, check my answer for any "strange" PHP problem ;)
(1) you don't need the refresh header if you have the location one
(2) add exit;
in the end
The second special case is the "Location:" header. Not only does it send this header back to the browser, but it also returns a REDIRECT (302) status code to the browser unless the 201 or a 3xx status code has already been set.
<?php
header("Location: http://www.example.com/"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
Depends on what you are trying to do. Are you trying to cause a redirect ? If this is the case you could simply use header('Location: http://www.example.com/');
but if you want to refresh after a certain amount of time you can use:
header( "refresh:5;url=wherever.php" );
echo 'You\'ll be redirected in about 5 secs. ';
echo 'If not, click <a href="wherever.php">here</a>.';
Got the example code from - http://php.net/manual/en/function.header.php - maybe worth a read too.