[英]Legacy Symfony project: PHP Warning: session_start(): The session id is too long or contains illegal characters
我正在嘗試在帶有 Ubuntu 18.x 的 Vagrant Box 中部署舊版 Symfony 1.4(實際上是 Symfon 1.5 通過 FriendsOfSymfony1 [1])項目。 我的 PHP 版本是 7.2.x(參見 [2]) 一切正常,站點加載,但出現此錯誤(並且無法完成對舊站點的登錄):
[Fri Feb 07 14:51:53.880189 2020] [php7:warn] [pid 2831] [client 10.0.2.2:63895] PHP 警告:session_start():會話 ID 太長或包含非法字符,有效字符為 az , AZ, 0-9 和 '-,' 在 /home/vagrant/swdev/lib/vendor/lexpress/symfony1/lib/storage/sfSessionStorage.class.php 第 95 行,引用: http://127.0.0.1: 8080/frontend_dev.php/registration/
[Fri Feb 07 14:51:53.880478 2020] [php7:warn] [pid 2831] [client 10.0.2.2:63895] PHP 警告:session_start():無法讀取會話數據:文件(路徑:/var/lib/ php/sessions) 在 /home/vagrant/swdev/lib/vendor/lexpress/symfony1/lib/storage/sfSessionStorage.class.php 中的第 95 行,引用: http : //127.0.0.1 : 8080 /frontend_dev.php/registration /
這里已經有討論了: session id太長或包含非法字符,有效字符是az, AZ, 0-9 和'-,'但是並沒有解決我的問題。
相關代碼片段(第 95 行)在這里:
設置session_id
的代碼在同一個文件中,第 52 行以后:
public function initialize($options = null)
{
$cookieDefaults = session_get_cookie_params();
$options = array_merge(array(
'session_name' => 'symfony',
'session_id' => null, // <=============== HERE
'auto_start' => true,
'session_cookie_lifetime' => $cookieDefaults['lifetime'],
'session_cookie_path' => $cookieDefaults['path'],
'session_cookie_domain' => $cookieDefaults['domain'],
'session_cookie_secure' => $cookieDefaults['secure'],
'session_cookie_httponly' => isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false,
'session_cache_limiter' => null,
), $options);
// initialize parent
parent::initialize($options);
這個鏈接提到這是一個 PHP 7.1 問題(我有 PHP 7.2!?),並且你不能使用null
作為session_id
(就像上面的代碼一樣)。 所以我改變了
'session_id' => null,
到
'session_id' => '',
然后我通過./symfony cc
清除緩存,然后重新啟動 apache,但仍然:我收到 PHP 警告重新會話 ID。
也許相關:查看遺留代碼,我意識到會話存儲是在我的factories.yml
文件中定義的,如下所示:
(snip)
storage:
class: sfCacheSessionStorage
param:
session_name: prx
cache:
class: sfMemcacheCache #[required] define the cache strategy
param:
servers: # Array of servers
localserver:
host: localhost # hostname or IP of mamcache server
port: 11211 # default memcache port
(snip)
Memcached 已經安裝並運行:
vagrant@ubuntu-bionic:~/swdev$ ps aux | grep -i memc
memcache 1002 0.0 0.3 424764 3036 ? Ssl 13:50 0:01 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -P /var/run/memcached/memcached.pid
vagrant 3289 0.0 0.1 13136 1108 pts/0 S+ 15:42 0:00 grep --color=auto -i memc
[1] 我使用 FriendsOfSymfony1 的更新而不是 Symfony 1.4
https://github.com/FriendsOfSymfony1/symfony1
[2] PHP 版本
PHP 7.2.24-0ubuntu0.18.04.2
問題不在於 FOS 代碼,而在於調用它的代碼。 您可以看到它將 FOS 數組與$options
數組合並。 請檢查此方法調用的堆棧跟蹤,並查看$options
參數的來源。 在那里解決它會解決 ID 太長的問題。
編輯:我使用您正在使用的 PHP 7.2 進行了一些檢查,我猜應該對那里的代碼進行一些 PR 並將代碼更改為:
$options = array_merge([
'name' => 'symfony',
/**
* Cannot be set becasue is not an session option
* @see: https://www.php.net/manual/en/session.configuration.php
*/
//'session_id' => null,
/**
* Cannot be set becasue of PERDIR
* @see: https://www.php.net/manual/en/configuration.changes.modes.php
*/
//'auto_start' => '0',
'cookie_lifetime' => $cookieDefaults['lifetime'],
'cookie_path' => $cookieDefaults['path'],
'cookie_domain' => $cookieDefaults['domain'],
'cookie_secure' => $cookieDefaults['secure'],
'cookie_httponly' => isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false,
/**
* Only allows specified string values, defaults to nocache, not null
*/
'cache_limiter' => 'nocache',
], $options);
刪除瀏覽器 cookie(來自 [1] 的提示)似乎可以解決問題。 但現在我有另一個錯誤[2]。 但那是關於 SO 的另一個問題。
[1] 見https://stackoverflow.com/a/28024487/5115219
[2] 下一個錯誤
[Fri Feb 07 18:22:01.701138 2020] [php7:warn] [pid 3200] [client 10.0.2.2:59612] PHP 警告:ini_set():會話處於活動狀態。 您此時無法在第 257 行的 /home/vagrant/swdev/lib/vendor/lexpress/symfony1/lib/user/sfBasicSecurityUser.class.php 中更改會話模塊的 ini 設置
然后嘗試登錄我的舊應用程序,我收到此錯誤日志:
[Fri Feb 07 18:22:10.272147 2020] [php7:warn] [pid 3610] [client 10.0.2.2:59628] PHP 警告:ini_set():會話處於活動狀態。 您此時無法在第 257 行的 /home/vagrant/swdev/lib/vendor/lexpress/symfony1/lib/user/sfBasicSecurityUser.class.php 中更改會話模塊的 ini 設置,參考: http://127.0.0.1: 8080/frontend_dev.php/registration/
[Fri Feb 07 18:22:10.360800 2020] [php7:warn] [pid 3610] [client 10.0.2.2:59628] PHP 警告:ini_set():會話處於活動狀態。 您此時無法在第 257 行的 /home/vagrant/swdev/lib/vendor/lexpress/symfony1/lib/user/sfBasicSecurityUser.class.php 中更改會話模塊的 ini 設置,參考: http://127.0.0.1: 8080/frontend_dev.php/registration/
[Fri Feb 07 18:22:10.826885 2020] [php7:warn] [pid 3521] [client 10.0.2.2:59629] PHP 警告:ini_set():會話處於活動狀態。 您此時無法在第 257 行的 /home/vagrant/swdev/lib/vendor/lexpress/symfony1/lib/user/sfBasicSecurityUser.class.php 中更改會話模塊的 ini 設置,參考: http://127.0.0.1: 8080/frontend_dev.php/registration/
[Fri Feb 07 18:22:11.717016 2020] [php7:notice] [pid 3521] [client 10.0.2.2:59629] 結果緩存驅動未初始化。,參考: http : //127.0.0.1 : 8080/ frontend_dev.php /登記/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.