无法通过使用标头功能重定向来访问其他页面上的会话?

时间:2018-08-21 10:08:42

标签: php html

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

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

0 个答案:

没有答案