Uploadify在上传之前销毁会话

时间:2013-10-12 03:27:41

标签: php jquery ajax session uploadify

我们都知道Uploadify存在会话问题。当我浏览帖子时,我找到了问题的解决方案,我需要通过ajax传递会话。

但问题是,每当我进入包含uploadify内容的页面时,它通常会在刷新后销毁会话。我甚至没有上传任何内容。'。

例如,我进入了一个包含uploadify脚本的页面。 没有做任何事情,我转到其他页面,它会自动重定向到登录页面 *,这意味着会话被销毁

在我上传文件之前,甚至在按下上传按钮之前,Uploadify是否会进行ajax调用?

有什么方法可以解决这个问题吗?

这是我的Ajax代码:

$(function() {
$('#file_upload1').uploadify({
       'formData'     : {
         'PHPSESSID': '<?=session_id()?>',
         'timestamp' : '<?php echo $timestamp;?>',
         'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
        },
        'swf'      : 'uploadify.swf',
        'uploader' : 'uploadify1.php?id=<? echo $id; ?>&state=<? echo strtolower($state); ?>'

         });
});

这是我的顶级PHP代码:

session_id($_POST['PHPSESSID']);

include "func.php";
sec_session_start();

sec_session_start();是一个功能。所以,sec_session_start();代码:

function sec_session_start() {
        $session_name = 'sec_session_id'; // Set a custom session name
        $secure = false; // Set to true if using https.
        $httponly = true; // This stops javascript being able to access the session id. 

        ini_set('session.use_only_cookies', 1); // Forces sessions to only use cookies. 
        session_set_cookie_params(86400);
        $cookieParams = session_get_cookie_params(); // Gets current cookies params.
        session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly); 
        session_name($session_name); // Sets the session name to the one set above.
        session_start(); // Start the php session
        session_regenerate_id(true); // regenerated the session, delete the old one.     
}

1 个答案:

答案 0 :(得分:0)

您是否尝试将PHPSESSID替换为sec_session_id

$(function() {
$('#file_upload1').uploadify({
       'formData'     : {
         '<?=session_name()?>': '<?=session_id()?>',
         'timestamp' : '<?php echo $timestamp;?>',
         'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
        },
        'swf'      : 'uploadify.swf',
        'uploader' : 'uploadify1.php?id=<? echo $id; ?>&state=<? echo strtolower($state); ?>'

         });
});

在您的PHP之上:session_id($_POST['sec_session_id']);

此外,session_name($session_name)应在session_set_cookie_params之前执行。

function sec_session_start() {
        $session_name = 'sec_session_id'; // Set a custom session name
        session_name($session_name); // Sets the session name to the one set above.
        $secure = false; // Set to true if using https.
        $httponly = true; // This stops javascript being able to access the session id. 

        ini_set('session.use_only_cookies', 1); // Forces sessions to only use cookies. 
        session_set_cookie_params(86400);
        $cookieParams = session_get_cookie_params(); // Gets current cookies params.
        session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly); 
        session_start(); // Start the php session
        session_regenerate_id(true); // regenerated the session, delete the old one.     
}