weixin_33690367 2014-11-24 05:13 采纳率: 0%
浏览 22

Ajax和PHP会话

I have a template based site that relies on persistent sessions throughout. Recently I needed to expand the session storage by defining the save handler for database storage. This works fine in the general scope of the classes within the framework however when any of the pages make an ajax request the session id get regenerated and if the form gets submitted the previous session is gone.

  <?php

 require_once('site-database.php');
 require_once('site-config.php');


 class FileSessionHandler

 {


 private $database;

 private $life_time;


 public function FileSessionHandler(){


 $this->life_time = get_cfg_var("session.gc_maxlifetime");

 $this->database = new database();

 $this->database->newConnection(db_host,db_user_name,db_user_pass,db_user_database);


 session_set_save_handler(
array(&$this,'open'),
array(&$this,'close'),
array(&$this,'read'),
array(&$this,'write'),
array(&$this,'destroy'),
array(&$this,'gc')
);

}

  • 写回答

2条回答 默认 最新

  • weixin_33726943 2014-11-24 06:42
    关注

    Please check whether you have started the session with session_start().

    评论

报告相同问题?