我正在使用 CodeIgniter 開發一個應用程式,并且我已經在 linux 服務器上部署了這個應用程式,我面臨的問題是這個錯誤
ERROR - 2022-01-06 11:48:16 --> Severity: Notice --> unserialize(): Error at offset 122 of 167 bytes /var/www/htmlaplib_core/libraries/Session.php 740,它阻止任何用戶登錄但是在我的本地開發環境中我沒有收到這個錯誤,我試圖在互聯網上找到解決方案,但我仍然無法收集解決方案。
這是在部署期間導致問題的代碼。
function _unserialize($data)
{
$data = @unserialize(strip_slashes($data));
if (is_array($data))
{
foreach ($data as $key => $val)
{
if (is_string($val))
{
$data[$key] = str_replace('{{slash}}', '\\', $val);
}
}
return $data;
}
return (is_string($data)) ? str_replace('{{slash}}', '\\', $data) : $data;
}
我會很感激我能得到的任何幫助
尤其是這條線 $data = @unserialize(strip_slashes($data));
這是$data之前變數的輸出@unserialize()
a:15:{s:10:"session_id";s:32:"aef2d2d8a8282132c6ebae6ccc4b94a8";s:10:"ip_address";s:3:"::1";s:10:"user_agent";s:114:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36";s:13:"last_activity";i:1641453560;s:9:"user_data";s:0:"";s:4:"LANG";s:2:"en";s:8:"identity";s:16:"[email protected]";s:8:"username";s:16:"[email protected]";s:5:"email";s:16:"admin@gmail";s:7:"user_id";s:1:"2";s:14:"old_last_login";s:10:"1641452323";s:14:"institution_id";s:1:"0";s:20:"employer_category_id";a:0:{}s:13:"user_group_id";s:1:"1";s:13:"employer_name";N;}
uj5u.com熱心網友回復:
問題很可能在于由于長度無效而導致的一些無效序列化資料。
對此的解決方案是重新計算序列化資料中的專案數以及這些專案的長度。
$recalculated_data = preg_replace_callback( '!s:(\d ):"(.*?)";!', function( $match ) {
return ( $match[1] == strlen( $match[2] ) ) ? $match[0] : 's:' . strlen( $match[2] ) . ':"' . $match[2] . '";';
}, $data );
unserialize( $recalculated_data );
另外請不要@在您的代碼中使用,因為這會阻止(重要)警告顯示。
有關序列化無效長度的更多資訊:如何修復因不正確的位元組計數長度而損壞的序列化字串?
uj5u.com熱心網友回復:
序列化本質上是將物件存盤為字串的一種方式。在表示中,您有一個部分告訴 php 即將到來的部分將是一定數量的字符長。這個數量在你的序列化字串中是錯誤的。
function _unserialize($data)
{
$data = preg_replace_callback(
'!s:(\d ):"(.*?)";!',
function($m) {
return 's:'.strlen($m[2]).':"'.$m[2].'";';
},
$data);
$data = unserialize($data);
if (is_array($data))
{
foreach ($data as $key => $val)
{
if (is_string($val))
{
$data[$key] = str_replace('{{slash}}', '\\', $val);
}
}
return $data;
}
return (is_string($data)) ? str_replace('{{slash}}', '\\', $data) : $data;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/405941.html
標籤:
下一篇:執行不繼續下一個功能
