PHP header redirect after ajax call does not have $_SESSION variables set


I found some jquery and ajax code that gets the browser window width and height. I do not know jquery or ajax, but I was very pleased to get it working, sort of. The script below works perfectly with a link to the next script that needs to run. Both $_SESSION variables are set properly and available. When I link to score.php through a header redirect, the $_SESSION variables apparently are not set because they are null in score.php. Timing issue?

I really do not want to have a link that the user has to click to continue. (These scripts are part of a system that requires a user to be "logged in".) Is there an easy solution to redirect to score.php so that the browserWidth and browserHeight values are available? I am ok with either accessing them as $_SESSION variables or as parameters (score.php?w=$browserWidth&h= . . .).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">  
<html xmlns="">  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
/ code from   
if(!isset($_POST['width']) || !isset($_POST['height'])) {  
  echo '  
  <script src="//"></script>  
  <script type="text/javascript">
  $(document).ready(function () {
    var height = $(window).height();
    var width = $(window).width();
      type: \'POST\',
      url: \'get_window_size.php\',
      data: {
        "height": height,
        "width": width
      success: function (data) {

$_SESSION['browserWidth'] =  $_POST['width'];  
$_SESSION['browserHeight'] =  $_POST['height'];  

echo '<a  href="score_image.php">Score Image</a>';    // THIS WORKS!

$location = 'Location: score_image.php';  
header("content-type: text/html; charset=utf-8");  


This video can help you solving your question :)
By: admin