首页 > 解决方案 > 无法通过使用标头功能重定向访问其他页面上的会话?

问题描述

您好我无法访问其他页面上的会话。我已经做了一切,但也无法解决。我用 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();
?>

请帮助我,因为我在互联网上找不到任何关于此的帮助。谢谢...

标签: phphtml

解决方案


推荐阅读