[英]some quick PHP and HTML help
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. 1:如果用户未登录,我希望将他们重定向回登录页面。
2: If a user is Logged in and they submitted a form I want them to be directed to the next page. 2:如果用户已登录并且提交了表单,我希望将他们定向到下一页。
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 谢谢
Use http headers instead. 请改用http标头。 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. 成功登录后,请不要忘记设置
$_SESSION['logged']=1
。 There are more methods of detecting that user sent form, but I prefer placing hidden input field with name="sent"
to each form. 有更多方法可以检测到该用户发送的表单,但是我更喜欢为每个表单放置
name="sent"
隐藏输入字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.