javascript - Failed to set session?

WBOY
Release: 2016-08-18 09:15:52
Original
1312 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

Reply content:

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!