Tuesday, April 23, 2013


Passing JavaScript variables to PHP

Using javascript variables in PHP Code
<script type="text/javascript">

width = screen.width;
height = screen.height;

if (width > 0 && height >0) {
    window.location.href = "http://localhost/main.php?width=" + width + "&height=" + height;
} else
    exit();

</script>

<?php
echo "<h1>Screen Resolution:</h1>";
echo "Width  : ".$_GET['width']."<br>";
echo "Height : ".$_GET['height']."<br>";
?>

0 comments:

Post a Comment