weixin_33747129 2016-07-16 23:04 采纳率: 0%
浏览 26

PHP不读取会话ID

On my webpage, I have a login form that creates a session - but PHP doesn't seem to be acknowledging it:

require_once('globals.php');
require_once('header.php');
if(!isset($_SESSION) || session_id() == '')
{
    $x = (isset($_SESSION));
    var_dump($_SESSION['username']);
    ?><br><?PHP
    var_dump(session_id());
    ?><br><?PHP
    var_dump($x);
    require_once('system/default.php');     
}
else
{
    require_once('system/' . $SystemScreens[$_SESSION['screen']]);
}
require_once('footer.php'); 

is producing:

NULL
string(0) ""
bool(false)


relavant part of login script (where $finalCheck is a boolean stating if the login was successful)

if($finalCheck)
    {
        session_start();

        $_SESSION['userID']         = $UserID;
        $_SESSION['username']           = $username;
        $_SESSION['accessLevel']        = $UserAccess;
        $_SESSION['screen']         = 1;

    }
    else
    {
        if(session_id() != '' || isset($_SESSION))
        {
            if (ini_get("session.use_cookies"))
            {
                $params = session_get_cookie_params();              
                setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]);
            }

            session_destroy();
        }

    }

I know that the login function is returning true because I have visual confirmation (result is returned to an AJAX request, and the page reloaded if true - which it does)

I can't figure out why everything is running as if the login is successful, but the session isn't being recognised after the reload occurs?

  • 写回答

1条回答 默认 最新

  • ?Briella 2016-07-16 23:24
    关注

    Put it after your PHP start tag

      <?php
      session_start();
      //... your code....
    
    
      //more code....  
    

    A basic session example

       <?php
           session_start();
           echo 'Welcome to page #1';
    
           $_SESSION['favcolor'] = 'green';
           $_SESSION['animal']   = 'cat';
           $_SESSION['time']     = time();
    
          // Works if session cookie was accepted
          echo '<br /><a href="page2.php">page 2</a>';
    
         // Or maybe pass along the session id, if needed
           echo '<br /><a href="page2.php?' . SID . '">page 2</a>';
         ?>
    

    session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

    When session_start() is called or when a session auto starts, PHP will call the open and read session save handlers. These will either be a built-in save handler provided by default or by PHP extensions (such as SQLite or Memcached); or can be custom handler as defined by session_set_save_handler(). The read callback will retrieve any existing session data (stored in a special serialized format) and will be unserialized and used to automatically populate the $_SESSION superglobal when the read callback returns the saved session data back to PHP session handling.

    For More Info : http://us3.php.net/function.session-start

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么