jQuery .load和Session ID不同步?

时间:2016-12-14 13:49:54

标签: javascript php jquery session

我想动态加载我的内容。它包含带有会话变量的php。我认为php工作得很好,但是会话变量不可访问。我的session_id有问题:

的index.php:

<Route
      path=":username"
      prepareParams={(params, { location }) => {
        const relayParams = params;
        if(location.state && location.state.pageSize) {
          relayParams.pageSize = location.state && location.state.pageSize;
        }
        return relayParams;
      }}
      component={ProductList}
      queries={UserQuery}
    />

我的Javascript:

<?php 
$session_name = 'sec_session_id';   
$secure = SECURE;

$httponly = true;

if (ini_set('session.use_only_cookies', 1) === FALSE) {
header("Location: ../error.php?err=Could not initiate a safe session (ini_set)");
    exit();
}

$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"],
    $cookieParams["path"], 
    $cookieParams["domain"], 
    $secure,
    $httponly);

session_name($session_name);
session_start();           
session_regenerate_id(); 
?>

<div class="sidebar">
<ul id="nav">
  <li><a class="selected" href="#" data-target="page1">Dashboard</a></li>
  <li><a  href="#" data-target="page2">Pages</a></li>

</ul> 
</div>
<?php echo session_id(); Print_r ($_SESSION);  ?>
<div class="content" id="main-content">
<?php 
include('pages/page1.php'); 
?>

我的加载内容php文件:

<script>
  $(document).ready(function(){
    // Set trigger and container variables
    var trigger = $('#nav li a'),
        container = $('#main-content');

    // Fire on click
    trigger.on('click', function(){
      // Set $this for re-use. Set target from data attribute
      var $this = $(this),
        target = $this.data('target');  

                if (!$this.hasClass("selected")) {
                        $("#nav li a").removeClass("selected");
                        $this.addClass("selected");

                }
                else {
                    event.preventDefault();
                }

      // Load target page into container
      container.load('pages/' + target + '.php');

      // Stop normal link behavior
      return false;
    });
  });
</script>

如果我首先刷新我的index.php,一切都正常加载。输出继电器:

fodnkd14c3l4jkeunlakg81he5数组([user_id] =&gt; 2)

fodnkd14c3l4jkeunlakg81he5数组([user_id] =&gt; 2)php工作

如果我通过jquery load加载我的page1.php,我得到这个输出:

fodnkd14c3l4jkeunlakg81he5数组([user_id] =&gt; 2)

ti7eqnmrrjmeckg5tln3ml2c83 Array()php工作

在jQuery .load之后,看起来像page1.php中的会话更改。没有session_regenerate_id();它仍然无法正常工作。我该如何解决这个问题?

0 个答案:

没有答案