在这里,在 PHP 代码中,我遇到了在有效登录后重定向页面的问题。
示例代码:
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
echo "<meta http-equiv='refresh' content='3;url=<?php echo "home.php"; ?>'>";
}
else{
?>
<META HTTP-EQUIV="refresh" content="5;URL=<?php print "index.php"; ?>">
<?php
echo "Wrong Username or Password";
}
?>
这里我想将页面重定向到 home.php。
如何修改以下行?
<meta http-equiv='refresh' content='3;url=<?php echo "home.php"; ?>'>
最佳答案
发送位置header :
header('Location: /home.php');
die;
在调用 <?php
之前,确保没有发送任何内容(包括 header
标签前后可能出现的空格。否则,它不会工作。
对于无效登录错误,您可以简单地再次显示带有错误消息的表单(而不是执行重定向)。
如果你坚持使用META标签:
echo "<meta http-equiv='refresh' content='3;url=home.php'>";
(您不需要字符串中的 php 打开/关闭标记)。
关于php - 使用元标记和 PHP 重定向页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4474242/