Session variable no longer persistate

I have wrote a code that has been working for the last past 3 month. Now suddenly, I noticed that my PHP _Session variable no longer persists between the different page for my login. Please note that the code actually works on local, but not on my server (papahost).

Here's a very simple version of what i'm trying to do (SESSION persists from class A to B):

class function.php

<?php 
function sec_session_start()
{
        //other code goes here 
        session_name('sec_session_id');
        $secure = SECURE;

        // This stops JavaScript being able to access the session id.
        $httponly = true;

        if (ini_set('session.use_only_cookies', 1) === FALSE) 
        {
           header("Location: ../error.php?err=8");
           session (ini_set)
           exit();
        }
       $cookieParams = session_get_cookie_params();
       session_set_cookie_params($cookieParams["lifetime"], 
       $cookieParams["path"], 
       $cookieParams["domain"], $secure, $httponly);
       //end of other code
    session_start();
}
?>



class a.php

<?php 
include_once 'function.php';
sec_session_start();
$_SESSION["test"] = "this is a test";
$url = "b.php";
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
echo '</noscript>'; 
exit;
?>



class b.php

<?php 
include_once 'includes/functions.php';
sec_session_start();
echo($_SESSION["test"]); 
?>

The expected output for class b.php is "this is a test" but the actual output is "" on my server since for an unknown reason, the session data is not persistant. As I said it works perfectly on local. Anyone has a clue what could be the problem? Could it be a problem from php.it or a CPanel property I missed?

I noticed that the PHPSESSID is not created after the line session_start() is executed in function.php.

Thank you for your help!


Bring session_start() over $secure = SECURE; in sec_session_start() . You should not define and assign any vars before session_start() .

Edit: Actually try to bring it step by step to upper levels and to somehow juggle in conjunction with the other session functions. Use no headers before it.

Edit: See here (point 1) the big problem caused by session_start() on second line, resolved very simple.

链接地址: http://www.djcxy.com/p/60248.html

上一篇: 在同一单元的类方法中使用属性而不是字段是一种不好的做法?

下一篇: 会话变量不再持久