Home >Backend Development >PHP Tutorial >javascript - Failed to set session?
I used an image upload plug-in: uploadify. Due to the 302 error when uploading under IE and Firefox, I passed the current session name session_name()
on the front end to the backend to re-establish the session, but I did the following, and the backend could I received the parameters of session_name()
, but when I re-established the session, it failed. How to solve it?
Front desk:
<code>//这是uploadify插件向后端传送数据的参数 'formData' : { 'timestamp' : '<?php echo $timestamp;?>', 'token' : '<?php echo md5('unique_salt' . $timestamp);?>', '<?php echo session_name();?>' : '<?php echo session_id();?>', //上面的session参数渲染后是这样:'PHPSESSID':'', },</code>
Backend:
<code>//这是一个公共的控制器的初始化方法 里面验证登陆 function __construct() { parent::__construct(); $session_name = session_name(); $post_session_name = $this->input->post($session_name); if (isset($post_session_name)) { //测试过 可以进入这里 session_id($post_session_name); //但是在这个地方好想设置会话失败 session_start(); } if ( !$this->session->valid_user() ){ //因为设置会话失败 这里通不过 前端返回302 redirect( module_url( 'common/login' ) ); } } </code>
I used an image upload plug-in: uploadify. Due to the 302 error when uploading under IE and Firefox, I passed the current session name session_name()
on the front end to the backend to re-establish the session, but I did the following, and the backend could I received the parameters of session_name()
, but when I re-established the session, it failed. How to solve it?
Front desk:
<code>//这是uploadify插件向后端传送数据的参数 'formData' : { 'timestamp' : '<?php echo $timestamp;?>', 'token' : '<?php echo md5('unique_salt' . $timestamp);?>', '<?php echo session_name();?>' : '<?php echo session_id();?>', //上面的session参数渲染后是这样:'PHPSESSID':'', },</code>
Backend:
<code>//这是一个公共的控制器的初始化方法 里面验证登陆 function __construct() { parent::__construct(); $session_name = session_name(); $post_session_name = $this->input->post($session_name); if (isset($post_session_name)) { //测试过 可以进入这里 session_id($post_session_name); //但是在这个地方好想设置会话失败 session_start(); } if ( !$this->session->valid_user() ){ //因为设置会话失败 这里通不过 前端返回302 redirect( module_url( 'common/login' ) ); } } </code>
Check the log to see if there is any error message? session_id
must be set before the session starts. Is the session already opened elsewhere before the __construct() call of this controller? Try adding session_abort()
in front of the session_id line?
The default is to save session_id through cookie. Please check whether the cookie is disabled or cleared