$_SESSION['pseudo'] = null 虽然它显然不应该
$_SESSION['pseudo'] = null while it clearly shouldn't
让我解释一下:我有 3 个页面(一个用于登录,一个过渡页面,以及您登录后我的主页。)
所以我想阻止访问我的应用程序,因为如果你断开你的会话,然后你 return 回来,即使你的会话关闭,你仍然可以访问该网站。所以这就是为什么我想使用 !isset($_SESSION['pseudo'])
.
第 1 页:
<form method="post" action="<?php echo serverRoot; ?>?action=connect">
<input required class="input-login" name="pseudo" type="text" id="pseudo" placeholder="Login">
<input required class="input-login" type="password" name="password" id="password" placeholder="Password">
<input id="connect" type="submit" value="Connect" />
</form>
如您所见,一旦提交,我们就会收到操作 "connect"。
这里是"connect"的情况:
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'connect':
{
showPage(adresseRoot . 'PHP/View/', 'FormConnection.php', "Connection");
break;
}
第 2 页:
$user = UserManager::getByPseudo($_POST['pseudo']);
if ($user->getPassword() === 'md5'.md5($_POST['password'].$_POST['pseudo']))
{
$_SESSION['pseudo'] = $user->getLogin();
$_SESSION['id'] = $user->getIdUtilisateur();
$message = '<p>Welcome ' . $user->getLogin() . ', !</p>';
echo $message;
header("refresh:3;url=Paths.php?action=listMenu");
}
如您所见,$_SESSION['pseudo']
现已设置。这不是空的!
然后你有 header("refresh:3;url=Paths.php?action=listMenu")
case 'listMenu':
{
if(!isset($_SESSION['pseudo'])){
showPage(adresseRoot . 'PHP/View/', 'FormConnection.php', "Connection"); //You don't have the right to go to the Website
break;
}
else{
showPage(adresseRoot . 'PHP/View/', 'ListMenu.php', "Main page"); //You have the right to go to the Website
break;
}
}
事实是,当我输入正确的登录名时,我被重定向到连接页面,而不是在我的主页上...Wtf?
有人可以帮我吗?
嗯,我找到了。
我在 Paths.php 的顶部添加了 session_start()
。
& 我删除了所有其他页面的 session_start()
。
让我解释一下:我有 3 个页面(一个用于登录,一个过渡页面,以及您登录后我的主页。)
所以我想阻止访问我的应用程序,因为如果你断开你的会话,然后你 return 回来,即使你的会话关闭,你仍然可以访问该网站。所以这就是为什么我想使用 !isset($_SESSION['pseudo'])
.
第 1 页:
<form method="post" action="<?php echo serverRoot; ?>?action=connect">
<input required class="input-login" name="pseudo" type="text" id="pseudo" placeholder="Login">
<input required class="input-login" type="password" name="password" id="password" placeholder="Password">
<input id="connect" type="submit" value="Connect" />
</form>
如您所见,一旦提交,我们就会收到操作 "connect"。
这里是"connect"的情况:
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'connect':
{
showPage(adresseRoot . 'PHP/View/', 'FormConnection.php', "Connection");
break;
}
第 2 页:
$user = UserManager::getByPseudo($_POST['pseudo']);
if ($user->getPassword() === 'md5'.md5($_POST['password'].$_POST['pseudo']))
{
$_SESSION['pseudo'] = $user->getLogin();
$_SESSION['id'] = $user->getIdUtilisateur();
$message = '<p>Welcome ' . $user->getLogin() . ', !</p>';
echo $message;
header("refresh:3;url=Paths.php?action=listMenu");
}
如您所见,$_SESSION['pseudo']
现已设置。这不是空的!
然后你有 header("refresh:3;url=Paths.php?action=listMenu")
case 'listMenu':
{
if(!isset($_SESSION['pseudo'])){
showPage(adresseRoot . 'PHP/View/', 'FormConnection.php', "Connection"); //You don't have the right to go to the Website
break;
}
else{
showPage(adresseRoot . 'PHP/View/', 'ListMenu.php', "Main page"); //You have the right to go to the Website
break;
}
}
事实是,当我输入正确的登录名时,我被重定向到连接页面,而不是在我的主页上...Wtf?
有人可以帮我吗?
嗯,我找到了。
我在 Paths.php 的顶部添加了 session_start()
。
& 我删除了所有其他页面的 session_start()
。