2011-03-26 66 views
0

可以说我有一个名为PHP会话空使用SSL?

https://url.com/testhttps://url.com/test2

class Test extends Application { 
    # put global things here 
    function __construct() { 
     $this->library ('sessions'); 
     $this->helper ('active'); 
    } 

    function test() { 
     $this->sessions->set('login',1); 
     echo session_id().'<br/>'; 
     echo $this->sessions->get('login'); 
    } 
    function test2(){ 
     if (is_get('d')) { 
      $this->sessions->del('login'); 
     } 
       echo session_id().'<br/>'; 
     echo $this->sessions->get('login'); 
    } 
} 

页当我使用http://url.com/testhttp://url.com/test2

它给我像

第1页的东西

326o42a9pblv48c9kb5va1mgorsf35gr39gu0tg8a6umr0rcdrgmasmmtbqvqm0dqa086bn3od07mpc11b65so62c1atrr3cgemaha1 
1 

第2页

326o42a9pblv48c9kb5va1mgorsf35gr39gu0tg8a6umr0rcdrgmasmmtbqvqm0dqa086bn3od07mpc11b65so62c1atrr3cgemaha1 
1 

但是当HTTPS

第1页

326o42a9pblv48c9kb5va1mgorsf35gr39gu0tg8a6umr0rcdrgmasmmtbqvqm0dqa086bn3od07mpc11b65so62c1atrr3cgemaha1 
1 

第2页

326o42a9pblv48c9kb5va1mgorsf35gr39gu0tg8a6umr0rcdrgmasmmtbqvqm0dqa086bn3od07mpc11b65so62c1atrr3cgemaha1 

1不见了。 问题是我想分享从页面测试到页面测试2的会话。

编辑* 这里是我的会话类

class Sessions { 
    private $config; 
    public function set($key, $value) { 
     if (isset ($_SESSION [$key])) { 
      return false; 
     } 

     if (! isset ($_SESSION [$key])) { 
      $_SESSION [$key] = $value; 
      return true; 
     } 
    } 

    public function get($key) { 
     if (! isset ($_SESSION [$key])) { 
      return false; 
     } 

     if (isset ($_SESSION [$key])) { 
      return $_SESSION [$key]; 
     } 
    } 

    public function del($key) { 
     if (! isset ($_SESSION [$key])) { 
      return false; 
     } 
     if (isset ($_SESSION [$key])) { 
      unset ($_SESSION [$key]); 
      return true; 
     } 
    } 

    public function flush() { 
     // do we still need this? 
     $_SESSION = array(); 
     session_destroy(); 
     $this->refresh(); 
    } 

    public function refresh() { 
     session_regenerate_id (true); 
    } 

    function __construct() { 
     $this->config = config ('sessions'); 

     # doing some importing things 
     ini_set ('session.cookie_httponly', $this->config ['cookie_httponly']); 
     ini_set ('session.gc_probability', $this->config ['gc_probability']); 
     ini_set ('session.gc_divisor', $this->config ['gc_divisor']); 
     ini_set ('session.hash_function', $this->config ['hash_function']); 
     ini_set ('session.gc_maxlifetime', $this->config ['gc_maxlifetime']); 

     # start the engine 
     session_start(); 
    } 
} 

的配置

$config['sessions'] = array(
     'gc_probability' => '0', 
     'gc_divisor' => '100', 
     # 'cookie_domain' => 'www.networks.co.id', 
     # http://us2.php.net/manual/en/session.configuration.php 
     'cookie_httponly' => FALSE, 
     # SHA512 
     'hash_function' => 'SHA512', 
     'gc_maxlifetime' => '1800' 
); 

感谢您寻找在

亚当·拉马丹

+0

你使用某种你想提到的框架吗? – Jakub 2011-03-26 14:09:07

+0

不使用自定义框架,这是奇怪的? – 2011-03-26 14:20:10

回答

2

我有一种感觉,你可能会使用PHP与Suhosin补丁,不是它的cas è?

如果是这样,在你的设置检查这个标志:

suhosin.session.cryptdocroot = On. 

这基本上告诉服务器,会话密钥取决于文档根目录,这让当您切换HTTP到HTTPS的改变。

编辑:你应该有这个设置为OFF在你的php.ini,或者使用多个INI文件,如Debian中的情况下,有可能是文件中像suhosin.ini在conf.d的子目录,其中PHP .ini驻留。不知道,是否可以通过ini_set()更改此设置

在无关的注释中,您确定要将gc_probability设置为0吗?这有效地禁用会话垃圾回收。

+0

是的,我正在使用suosin im检查它 – 2011-03-26 15:22:14

+0

好吧,别忘了评论它是怎么回事 – 2011-03-26 16:09:01

+0

即时通讯仍然找到如何打开它像ini_set('suhosin.session.cryptdocroot','On'); ? – 2011-03-27 04:42:50