I'm writing an application which uses cookie-based sessions for authentication. All was well until I tried to integrate the uploadify jQuery plugin into my site. I need uploadify to send the files to my upload.php
file. When I check the existence of any preknown session variables in that upload.php
script, I get nothing. I've tried print_r($_SESSION)
and got an empty array.
I'm not sure if this a problem with my php sessions code or my jquery uploadify code. I'm somewhat new at both.
/** INSIDE JQUERY **/
$('.fileUploadify').uploadify({
'scriptData': {'filesUploaded':'1','PHPSESSID' : <?php echo json_encode(session_id()); ?>},
...
/** UPLOAD.PHP **/
if(isset($_REQUEST['PHPSESSID']))
session_id($_REQUEST['PHPSESSID']);
if(!isset($_GET['logout']) && isset($_SESSION['user']) && $_SESSION['ipadd'] == $_SERVER['REMOTE_ADDR']) {
define('USERHASH',$_SESSION['user']);
require_once('lib/ez_sql_core.php');
require_once('lib/ez_sql_sqlite.php');
require_once('lib/functions.php');
$db = new ezSQL_sqlite('./'.USERHASH.'/','fileInformationBase.sqlite');
$mdb = new ezSQL_sqlite('./','fileServMain.sqlite');
$stats = $mdb->get_row("SELECT ID,bandwidthUsage,lastL开发者_StackOverflow社区ogin,...
} else die('No no no');
The upload.php
returns 'No no no` everytime. I've checked the session id, and it is sending to upload.php correctly.
On my normal page headers I'm not having this problem, where I'm simply starting the authorization section with session_start()
and then the same if(isset($_SESSION['user']) && $_SESSION['ipadd] ...) {
line, which is working as expected.
Edit
This is the generated code for the jQuery script above
'scriptData': {'filesUploaded':'1','PHPSESSID' :"m3vgn7j6a7nd3ckppnio1ln3e1" }
And putting an echo $_REQUEST['PHPSESSID']
in the upload.php script prints out
'sjojolnjtcutbomceh50os3kg4'
If you are telling your plugin to send session id via regular GET/POST parameter, it has to be enabled on the server. You should first debug this by viewing the network requests made from your browser (Firefox + FireBug addon is a good choice) to see whether or not your session id reaches the server.
If it does, consider .htaccess with:
php_flag session.use_trans_sid on
php_flag session.use_only_cookies off
Somehow the sessions that flash was seeing were old values. I don't know if they are cached or what. In any case, I had to "flush" the system out by deleting all SESSION cookies and starting over. Then it picked up the correct values. Hope this saves someone in the future some time.
精彩评论