-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix session_regenerate_id issue when using redis as the session handler #12331
Fix session_regenerate_id issue when using redis as the session handler #12331
Conversation
…er in php7. No session handler should return null for read method. it should return an empty string is the key is not found
Some test if it's fixed could be good. |
@@ -118,7 +118,8 @@ class Redis extends Adapter | |||
*/ | |||
public function read(sessionId) -> string | |||
{ | |||
return (string) this->_redis->get(sessionId, this->_lifetime); | |||
let res = (string) this->_redis->get(sessionId, this->_lifetime); | |||
return res == null ? "" : res; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after let res = (string) ....
the res
wont be a null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also you missed var res
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need to instantiate the 'res' variable before this line:
var res;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and we use tabs for zep files instead of spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
php -a
Interactive mode enabled
$res = '';
php > var_dump($res == null);
php shell code:1:
bool(true)
There is a problem with current implementation. The line
is returning null when the session key is not in store (when using redis session handler) This causes a fatal error when calling session_regenerate_id I was using phalcon with php7 and redis session handler and had to extend it and use the extended php session handler with following method.
May be someone can apply a fix based on this |
How this is returning null when it should be casted to |
Why you didn't added |
Fixed in the git clone git@github.com:phalcon/cphalcon.git
cd cphalcon
git checkout 3.0.x
zephir fullclean
zephir build |
// always will return string, not null
return (string) $this->_redis->get($sessionId, $this->_lifetime);
// just try
var_dump(null);
var_dump((string) null); |
@sergeyklay when the null casted to string you might not be getting a null in zephir. But when the redis.zep is extended and called in php7 it is retuning null to php7. Please check the screenshot attached. @Jurigag the code in screenshot is php. $this->_redis->get calls the get function in phalcon redis adapter compiled from branch 3.0.x. But as you can see it is retuning null. (even though you have casted the result from redis store to string). This breaks "session_regenerate_id" in php7. I extended the pahlcon redis session handler and used it as my application session handler to fix this issue. |
@thilinah Please see at |
Provide please small script to return non-string, real null. |
Fix session_regenerate_id issue when using redis as the session handler in php7. No session handler should return null for read method. it should return an empty string is the key is not found