昨天試著把系統(tǒng)移植到PHP 7.1上執(zhí)行看看正歼,系統(tǒng)裝完瀏覽器一開(kāi)能看到登入畫(huà)面窑滞,正高興著定血,結(jié)果就發(fā)現(xiàn)登入不進(jìn)去转砖,看起來(lái)像是Session方面的問(wèn)題须鼎。
問(wèn)題原因:
在 system/libraries/Session/Session.php:129
// Sanitize the cookie, because apparently PHP doesn't do that for userspace handlers
if (isset($_COOKIE[$this->_config['cookie_name']])
&& (
! is_string($_COOKIE[$this->_config['cookie_name']])
OR ! preg_match('/^[0-9a-f]{40}$/', $_COOKIE[$this->_config['cookie_name']])
)
)
{
unset($_COOKIE[$this->_config['cookie_name']]);
}
這邊會(huì)檢查存在$_COOKIE的session id格式是否正確,剛好我現(xiàn)在的格式不符(你可以透過(guò)cookie值或是session_id()查看)府蔗,所以這個(gè)cookie值就被清掉了晋控,導(dǎo)致session值也取不出來(lái)。
解決方法1
然後找到官網(wǎng)上的說(shuō)明(如下)姓赤,原來(lái)session ID的長(zhǎng)度現(xiàn)在是可以設(shè)定的赡译,然後我修改php.ini把長(zhǎng)度變更為40,還是不行不铆。
** session.sid_length **
session.sid_length allows you to specify the length of session ID string. Session ID length can be between 22 to 256. The default is 32. If you need compatibility you may specify 32, 40, etc. Longer session ID is harder to guess. At least 32 chars is recommended.Compatibility Note: Use 32 for session.hash_func=0 (MD5) and session.hash_bits_per_character=4,session.hash_func=1 (SHA1) and session.hash_bits_per_character=6. Use 26 for session.hash_func=0 (MD5) and session.hash_bits_per_character=5. Use 22 for session.hash_func=0 (MD5) andsession.hash_bits_per_character=6. You must configure INI values to have at least 128 bits in session ID. Do not forget set appropriate value to session.sid_bits_per_character, otherwise you will have weaker session ID.
**Note**: This setting is introduced in PHP 7.1.0.
還有一個(gè)問(wèn)題蝌焚,看到修改後的session id雖然長(zhǎng)度對(duì)了,但有a-f以外的字元誓斥,繼續(xù)找...
session.sid_bits_per_character
session.sid_per_character allows you to specify the number of bits in encoded session ID character. The possible values are '4' (0-9, a-f), '5' (0-9, a-v), and '6' (0-9, a-z, A-Z, "-", ","). The default is 4. The more bits results in stronger session ID. 5 is recommended value for most environments.
**Note**: This setting is introduced in PHP 7.1.0.
再把這個(gè)改為4只洒,然後就可以了。
解決方法 2
回頭到Codeigniter的GitHub查劳坑,這問(wèn)題在目前最新的版本(3.1.3)已經(jīng)修改了红碑,所以你也可以考慮把系統(tǒng)底層升級(jí)。