我的服务器运行在PHP 5.2.9中,当我使用刷新和头函数时,它不起作用。这是我的代码
header("location: index.php");
header( "Refresh: 0;" );
以前我在另一台服务器上工作,它工作正常。我该如何解决这个问题?
这是我的完整代码
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和Refresh都需要一个绝对URI(它是"Location"而不是"Location")。
试试这个:
header('Location: http://absolute.uri/file.ext');
如果这没有帮助,请检查我的回答是否有任何"问题";奇怪的";PHP问题;)
这取决于你想做什么。你想引起重定向吗?如果是这种情况,你可以简单地使用header('Location: http://www.example.com/');
,但如果你想在一定时间后刷新,你可以使用:
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>.';
示例代码来自-http://php.net/manual/en/function.header.php-也许也值得一读。
(1)如果位置为一个,则不需要刷新标头
(2) 在末端中添加exit;
第二种特殊情况是"位置:"标题。它不仅将该报头发送回浏览器,但是它也返回REDIRECT(302)浏览器的状态代码,除非201或3xx状态代码已经已设置。
<?php
header("Location: http://www.example.com/"); /* Redirect browser */
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
那么最好使用JavaScript。在之前附加此代码
<script> setTimeout(function() { window.location = "index.php"; }, 2000); </script>