I am getting a screen resolution through XMLHttpRequest. I am opening a show_content.php file with xmlhttp.open that contains screen resolution variables which I pull with the GET Method.


This works!

and showing this file with the variables in a following div

<div id="txtResolution"></div>

This part works as well!

PROBLEM: This div ( show_content.php ) contains screen resolution variables that I would like to use throught the rest of the code outside of it but I can not pass them somehow. How can I get those variables to be passed to the original code.

I used the GET method but can not pass the variables to the original code outside the show_content.php I have tried with GLOBALS and Sessions as well but no luck

Here ist the code. Everything works properly but I can not pass the variables from the "txtResolution" div to the rest of the code

function showResolution(field_id)
var xmlhttp;
if (field_id.length==0)
if (window.XMLHttpRequest)
 {// code for IE7+, Firefox, Chrome, Opera, Safari
 xmlhttp=new XMLHttpRequest();
 {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 if (xmlhttp.readyState==4 && xmlhttp.status==200)

var winW = 630, winH = 460;
if (document.body && document.body.offsetWidth) {
 winW = document.body.offsetWidth;
 winH = document.body.offsetHeight;
if (document.compatMode=='CSS1Compat' &&
document.documentElement &&
document.documentElement.offsetWidth ) {
 winW = document.documentElement.offsetWidth;
 winH = document.documentElement.offsetHeight;
if (window.innerWidth && window.innerHeight) {
 winW = window.innerWidth;
 winH = window.innerHeight;
var queryString = "?width=" + winW + "&height=" + winH;


This looks good. Show PHP code where you try to set variables to global or session.



/////// session could not pass the variable

/////// GLOBALS  can not pass the variable

Your code raise PHP error if variable not set - must be check if(isset($_GET['height'])){ $height=$_GET['height']; } or much better you can use filtered variables PHP - filter_input

$height = filter_input(INPUT_GET, 'height', FILTER_VALIDATE_INT);
$width = filter_input(INPUT_GET, 'width', FILTER_VALIDATE_INT);

Then set as session variables only if variable is not NULL

if($width !== NULL){
    $_SESSION['width'] = $width;
if($height !== NULL){
    $_SESSION['height'] = $height;

Otherwise your session variables always set to NULL if not set new values on each http request - in fact it does not work as a session variables