dtl85148 2018-08-21 10:08
浏览 69

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

Hi I am having trouble accessing session on other pages. I have done everything but can't solve it either. I start each page with session_start(). I have a form that gets username name and password and sends it to another page that saves this information in session array and redirects to the previous page but it seems like the session is not changed. It would be hard to help and understand without the code so here it is:

In my 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");
     ?>

and the page that handles the form input:

<?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();
?>

Please help me as I can't find any help on internet about this. Thanks...

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 VMware 云桌面水印如何添加
    • ¥15 用ns3仿真出5G核心网网元
    • ¥15 matlab答疑 关于海上风电的爬坡事件检测
    • ¥88 python部署量化回测异常问题
    • ¥30 酬劳2w元求合作写文章
    • ¥15 在现有系统基础上增加功能
    • ¥15 远程桌面文档内容复制粘贴,格式会变化
    • ¥15 这种微信登录授权 谁可以做啊
    • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
    • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”