基本上我会告诉你我想做什么.
1:如果用户未登录,我希望将他们重定向回登录页面.
2:如果用户已登录并且他们提交了表单,我希望将其定向到下一页.
我已经尝试了元刷新,但我似乎只能让它与其中一个一起工作.
你能告诉我最好的办法是什么吗?
我目前使用的代码是
<meta http-equiv="refresh" content="0;index.php">
<meta http-equiv="refresh" name="myidentifier" content="0;mystats.php">
Run Code Online (Sandbox Code Playgroud)
谢谢
请改用http标头.例如:
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);
}
Run Code Online (Sandbox Code Playgroud)
$_SESSION['logged']=1成功登录后不要忘记设置.有更多方法可以检测用户发送的表单,但我更喜欢将隐藏的输入字段放在name="sent"每个表单中.
| 归档时间: |
|
| 查看次数: |
102 次 |
| 最近记录: |