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.php
input2.php: //Takes file name and puts into session
<?php
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
$_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
<?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();
?>
<?php
$_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
<?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();
?>
<?php
/*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:
<?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();
?>
// Should be
<?php
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.
精彩评论