Some session variables disappear in ajax request

Ok, I have the following set of pages. They take user information, and put them into the php session variables so that, in the end, an ajax enabled page can use them. The issue is that only some of these session vars are available to the server.Here is the flowinput.php => input2.php,input2.php => control.php,…

via PHP Website Development » Search Results » ajax:

Some session variables disappear in ajax request

Ok, I have the following set of pages. They take user information, and put them into the php session variables so that, in the end, an ajax enabled page can use them. The issue is that only some of these session vars are available to the server.
Here is the flow
input.php => input2.php,
input2.php => control.php,
control.php calls ajax requests to updateAjax.phpinput2.php: //Takes file name and puts into session
session_start();
header(“Cache-Control: no-cache, must-revalidate”); // HTTP/1.1
header(“Expires: Sat, 26 Jul 1997 05:00:00 GMT”); // Date in the past
?>
$_SESSION = array();
$_SESSION[‘file’] = $_FILES[‘file’][‘name’];
mkdir(“/blend/”. $_FILES[‘file’][‘name’]);
mkdir(“/blend/” . $_FILES[‘file’][‘name’] . “/frames”);
move_uploaded_file($_FILES[“file”][“tmp_name”], “/blend/”. $_SESSION[‘file’] . “/scene.blend”);
?>control.php //Takes user input from fourms and inputs it into session vars
header(“Cache-Control: no-cache, must-revalidate”); // HTTP/1.1
header(“Expires: Sat, 26 Jul 1997 05:00:00 GMT”); // Date in the past
session_start();
?>
$_SESSION[‘endFrame’] = $_POST[‘frameEnd’] – 0;
$_SESSION[‘format’] = $_POST[‘format’];
$_SESSION[‘currFrame’] = $_POST[‘frameStart’] – 1;
?>When i use var_dump to examine vars in the session, its all good until updateAjax.php is called
updateAjax.php
header(“Cache-Control: no-cache, must-revalidate”); // HTTP/1.1
header(“Expires: Sat, 26 Jul 1997 05:00:00 GMT”); // Date in the past
session_start();
?>
/*for blender internal render engine*/
init();

function init()
sendInfo();

function sendInfo()
$output = array();
$output[‘status’] = $_SESSION[‘file’];
$output[‘currFrame’] = $_SESSION[‘currFrame’]; //Var is -1!
$output[‘lastFrame’] = $_SESSION[‘endFrame’]; //var is 0!
echo json_encode($output);

?>output[‘lastframe’] and currframe are equal to 0 and -1 respectively, no matter what you acually put in on the previous pages. the session[file] however is correct…
To sum it all up:
Go to input.php and upload your file
session[‘file’] is available;
go to input2.php
session[‘currframe’], endframe, and format are correct
go to control.php
all session vars are available
updateAjax.php can only access session[‘file’], not any others
Any ideas at to what my problem might be? Thanks for helping me out :) , and ask if you need more info, ill be glad to help
…………………………………..

In control.php and updateAjax.php, you cannot send headers before calling session_start(). Invert the order of these:
header(“Cache-Control: no-cache, must-revalidate”); // HTTP/1.1
header(“Expires: Sat, 26 Jul 1997 05:00:00 GMT”); // Date in the past
session_start();
?>

// Should be
session_start();
header(“Cache-Control: no-cache, must-revalidate”); // HTTP/1.1
header(“Expires: Sat, 26 Jul 1997 05:00:00 GMT”); // Date in the past
?>PHP should be issuing a warning about this. Check your web server error logs.

For more info: Some session variables disappear in ajax request

PHP Website Development » Search Results » ajax

Some session variables disappear in ajax request

Share this post:

Related Posts

Leave a Comment