Page 1 of 1

I can't compare two variable - problem with data type

Posted: Mon Jun 07, 2010 1:46 am
by jothish
Hi Friends,

I want to write a program to find out the screen resolutions and if the screen resolution is not equal to 1024*768, I need to show an error.
So by using below script I will get the W and H of screen resolutions.
But I can't compare that. Please see the code I used.

Code: Select all

<?php
$w = '<script  language="JavaScript">document.write(Number(screen.width));</script>';
$h = '<script  language="JavaScript">document.write(Number(screen.height));</script>';
			
if($w<1024){
  echo "Please set your screen resolution greeter than 1024x768";
}
?>
But It is not working.
if I print " var_dump($w) ", it shows as its data type is "string",
So I tried to user (int) to convert type and settype($w,'integer');
But I still not able to compare.
Can you help me to solve this problem.
regards
Jothish

Re: I can't compare two variable - problem with data type

Posted: Mon Jun 07, 2010 3:45 am
by markusn00b
You must understand the separation between PHP and JavaScript.

When you make a request to an HTTP server, if a type handler matches the file type to one specified as being PHP, the server invokes the PHP module to parse and return the page. PHP sends its data to buffers that your server then use to give data to the browser. At this point it is important to realise PHP has left the building. Once your text has appeared on screen, you do not have a connection to PHP anymore.

JavaScript, if it's not running as the server-side programming language -- which is possible now -- will be running as a client-side, in-browser programming language. Considering that PHP does not run in the browser, as mentioned before, it runs in the server, your JavaScript cannot communicate with PHP (unless you use AJAX or WebSockets).

In fact, you do not need PHP here at all. Simple just send the JavaScript to the browser in an HTML file and it will be run properly.

Mark.