I have a page with some user selectable options and a button that, when clicked, runs a PHP script and then refreshes a div with another PHP file that uses a session variable that is created at the end of the first PHP script. If the user presses the button again, with different options selected, the div is updated using the newly replaced session variable. The problem is that sometimes, perhaps 1 in 10 times or so, the old session variable data is loaded. I suspect that the second PHP file is catching the variable too early, before it has been updated, but I tried unsetting the session variable at various points with out any luck.
First PHP file:
session_start();
$needle = array();
foreach($_POST['checkboxes'] as $key => $value){
$needle[] = "$value";
}
// code that processes the values from needle and outputs $data
unset($_SESSION['data']);
$_SESSION['data']=$data;
Second PHP file:
session_start();
echo $_SESSION['data'];
Javascript:
$(".userdata").click(function() {
$.post("first.php", $("form#checkboxes").serialize());
});
$(function() {
$("#button").click(function() {
$("#div").load('second.php')
})
})