Last updated on January 25th, 2022 at 05:37 pm

Here is a script that will pass variables from Javascript to PHP. As an example I am using Javascript to find out the screen resolution of a visitor. My use-case require my visitors screen width and height to be passed to a PHP script that does some processing in the background. Likewise you might have a different requirement but can utilize the script below to get some idea on how this can be done.

<script language="javascript" 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>

As you can see the above Javascript is passing variables ie the width and height to a php page [MAIN.php]

Leave a Reply

Your email address will not be published. Required fields are marked *