2013-10-12 42 views
0

我們都知道Uploadify存在會話問題。當我瀏覽帖子時,我發現瞭解決問題的方法,我需要通過ajax傳遞會話。Uploadify正在銷燬上傳之前的會話

但問題是,每當我去一個包含uploadify的頁面時,通常會在刷新後破壞Session。我甚至沒有上傳任何東西。'。

例如,我到了一個包含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.  
} 
+0

你能更清楚地描述出了什麼問題,並顯示你用來解決問題的代碼嗎? –

+0

查看編輯代碼 –

+0

你怎麼知道這是會議行動?你確定沒有其他JavaScript錯誤導致頁面重新加載嗎? –

回答

0

您是否嘗試過更換PHPSESSIDsec_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.  
}