php - 无法通过使用标头功能重定向访问其他页面上的会话?
问题描述
您好我无法访问其他页面上的会话。我已经做了一切,但也无法解决。我用 session_start() 开始每一页。我有一个表单,它获取用户名和密码并将其发送到另一个页面,该页面将此信息保存在会话数组中并重定向到上一页,但似乎会话没有更改。如果没有代码,很难帮助和理解,所以这里是:
在我的 sigin.php 中,
<?php
session_start();
$_SESSION['errorMessage']='0';
include("header.html");
if($_SESSION['loggedin']){
print("<div class='pageContent'>
<h2>Sign in</h2>
<form method='POST' action='sign.php'>
<input type='text' maxlength='20' name='username' placeholder='Username'/ required><br/>
<input type='text' maxlength='30' name='password' placeholder='Password'/ required><br/>
<input type='submit' name='submit' value='Sign in' style='padding:0.5em;margin-left:45%;font-family:cursive,helvetica,Arial; color:darkred;cursor:pointer;'/>
</form>");
if($_SESSION['errorMessage']){
print("<div style='font-family:inherit' color:red' margin:1em;'>"
. $_SESSION['errorMessage'] . "</div>");
}
print("<div style='font-family:inherit;padding-
bottom:1.5em;margin:1em;'>
Don't have an account? <a href='' style='text-
decoration:none;'>Click here</a>
to sign up.
</div>
</div>");
}
else{
print("<div class='pageContent'>
<h2>You are logged in.</h2>
</div>
");
}
include("footer.html");
?>
以及处理表单输入的页面:
<?php
session_start();
if($_SESSION['username']==$_POST['username']&&$_SESSION['password']==$_POST['password'])
{
$_SESSION['loggedin']='true';
$_SESSION['errorMessage']='';
}
else{
$_SESSION['errprMessage']='The username and password combination is invalid!';
$_SESSION['loggedin']='false';
}
header("Location:signin.php");
exit();
?>
请帮助我,因为我在互联网上找不到任何关于此的帮助。谢谢...
解决方案
推荐阅读
- haskell - 如何在 Haskell 中解决这个问题?
- python-3.x - 将列表中的值分配给字典列表中的特定值
- asp.net - 将 User.Identity.Name 分配给变量保持为空
- mysql - 更改 100M 行 Amazon RDS 表以添加新列
- php - Wordpress如何删除父类别并仅保留带有帖子标题的子类别
- gnuradio - Gnu Radio Companion 3.8 WX GUI 替换
- python - 在python中将非统一文件读入单个数组
- javascript - 表单控制输入中的 React js useReducer 钩子
- flutter - Flutter 如何使用 cookie 在浏览器中打开 url
- mysql - 统计 SQL 中属于另一个元素的元素数量(每个品牌的产品数量)