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,lastLogin,...
} 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.
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'
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.