2013-12-16 68 views
1

這有個大問題。我在Apache(Arch Linux)上開發了一個本地PHP項目,在線PHP將會話密鑰設置爲null。我使用Class :: serialize和Class :: unserialize保存會話中的對象。而這就是我的PHP代碼此功能:PHP Session next page call null

public function serialize() { 
    $data = new \stdClass(); 
    $data->content = $this->content; 
    $data->key = $this->key; 
    $data->file = $this->file; 

    return serialize($data); 
} 
public function unserialize($data) { 
    $data = unserialize($data); 

    $this->content = $data->content; 
    $this->key = $data->key; 
    $this->file = $data->file; 
    $this->crypt = new \Kryptomat\Crypt\Mcrypt($this->key); 
} 

我的php.ini:

session 

Session Support enabled 
Registered save handlers files user 
Registered serializer handlers php_serialize php php_binary 

Directive Local Value Master Value 
session.auto_start Off Off 
session.cache_expire 180 180 
session.cache_limiter nocache nocache 
session.cookie_domain no value no value 
session.cookie_httponly Off Off 
session.cookie_lifetime 0 0 
session.cookie_path//
session.cookie_secure Off Off 
session.entropy_file /dev/urandom /dev/urandom 
session.entropy_length 32 32 
session.gc_divisor 1000 1000 
session.gc_maxlifetime 1440 1440 
session.gc_probability 1 1 
session.hash_bits_per_character 5 5 
session.hash_function 0 0 
session.name PHPSESSID PHPSESSID 
session.referer_check no value no value 
session.save_handler files files 
session.save_path no value no value 
session.serialize_handler php php 
session.upload_progress.cleanup On On 
session.upload_progress.enabled On On 
session.upload_progress.freq 1% 1% 
session.upload_progress.min_freq 1 1 
session.upload_progress.name PHP_SESSION_UPLOAD_PROGRESS PHP_SESSION_UPLOAD_PROGRESS 
session.upload_progress.prefix upload_progress_ upload_progress_ 
session.use_cookies On On 
session.use_only_cookies On On 
session.use_strict_mode Off Off 
session.use_trans_sid 0 0 

這是服務器的php.ini:

session 

Session Support enabled 
Registered save handlers files user 
Registered serializer handlers php php_binary wddx 

Directive Local Value Master Value 
session.auto_start Off Off 
session.cache_expire 180 180 
session.cache_limiter nocache nocache 
session.cookie_domain no value no value 
session.cookie_httponly Off Off 
session.cookie_lifetime 0 0 
session.cookie_path//
session.cookie_secure Off Off 
session.entropy_file no value no value 
session.entropy_length 0 0 
session.gc_divisor 100 100 
session.gc_maxlifetime 1440 1440 
session.gc_probability 1 1 
session.hash_bits_per_character 4 4 
session.hash_function 0 0 
session.name PHPSESSID PHPSESSID 
session.referer_check no value no value 
session.save_handler files files 
session.save_path /tmp /tmp 
session.serialize_handler php php 
session.upload_progress.cleanup On On 
session.upload_progress.enabled On On 
session.upload_progress.freq 1% 1% 
session.upload_progress.min_freq 1 1 
session.upload_progress.name PHP_SESSION_UPLOAD_PROGRESS PHP_SESSION_UPLOAD_PROGRESS 
session.upload_progress.prefix upload_progress_ upload_progress_ 
session.use_cookies On On 
session.use_only_cookies On On 
session.use_trans_sid 1 1 
+1

你是否在所有關注的頁面上使用'session_start();'? – reikyoushin

+1

「我有一個大問題」今天感覺有點德國,我明白了。 :) –

回答

0

開始會議? 啓動會議呼叫session_start();

你是不是在保存會話中的數據,採用序列$_SESSION['data'] = $data;

然後下一個頁面保存在會話中的數據可以通過$_SESSION['data']檢索這些數據之後。之後,使用您的反序列化函數對序列化對象進行序列化。

希望它能幫助你。

+0

我不想保存會話中的數據。該對象在會話中。如果此對象包含Serializable,則會話將自動調用serialize和unserialize方法。或不? – Marvvvv

+0

亞..會話將在內部做序列化。 –