New to jquery: unable to pass var to php via GET reload

New to jquery: unable to pass var to php via GET reload

Hi there folks,

I'm trying to pass some variables( browser width and height) to my php script.  I've read that I need to reload the page and pass the vars via GET so I can use them in my php script.  I've tried to do this with some cobbled stuff I've found in tutorials and elsewhere on the web, but am failing miserably.

  1. <?php
  2. if(ISSET($_GET['w'])){
  3.     /* Browser vars have been passed. */
  4.     echo("<!DOCTYPE html>
  5.     <html>
  6.     <head>
  7.     <meta http-equiv='content-type' content='text/html; charset=UTF-8'>
  8.     <title>window size</title>
  9.      
  10.     <script type='text/javascript' src='http://code.jquery.com/jquery-1.11.0.min.js'></script>
  11.      
  12.     Window size is:
  13.    
  14.     Width: ".$_GET['w']."<br />
  15.     Height: ".$_GET['h']."
  16.      
  17.     </body>
  18.     </html>
  19.     ");
  20. }else{
  21.     /* Use jquery to retrieve window size and refresh page. */
  22.     echo("<!DOCTYPE html>
  23.     <html>
  24.     <head>
  25.     <meta http-equiv='content-type' content='text/html; charset=UTF-8'>
  26.       <title>window size</title>
  27.      
  28.     <script type='text/javascript' src='http://code.jquery.com/jquery-1.11.0.min.js'></script>
  29.      
  30.     <script type='text/javascript'>//<![CDATA[
  31.     // jQuery
  32.     function jqUpdateSize(){
  33.         // Get the dimensions of the viewport
  34.         var width = $(window).width();
  35.         var height = $(window).height();
  36.         $('#jqWidth').html(width);
  37.         $('#jqHeight').html(height);
  38.     };
  39.     $(document).ready(jqUpdateSize);    // When the page first loads
  40.     $(window).resize(jqUpdateSize);     // When the browser changes size
  41.    
  42.     });//]]> 
  43.     </script>
  44.     </head>
  45.     <body>
  46.    
  47.     <script type='text/javascript'>
  48.     window.location.href = window.location.href+'?w='+width&h=+height;
  49.     </script>
  50.    
  51.     You shouldn't be able to see this.
  52.      
  53.     </body>
  54.     </html>");
  55. }
  56. ?>

This is just showing the body of the page that's supposed to be reloading with the vars.  I've tried moving the window.location script to the head, both inside and outside the jquery function and in the body of the page.

If anyone could help me get this working, I'd be greatly appreciative.

Thanks for your time!