1

Possible Duplicate:
Data transfer from JavaScript to PHP.

How can i get the browser's height and width to php? Like a data transfer from javascript to php? With using innerHeight and InnerWidth, i think.

(I just need to show user small picture if he has small screensize and big if big and without a data about screensize i cant do it)

I have like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<link rel="stylesheet" href="css/slideshow.css" type="text/css" /> 

<script> 
document.write('script.php?screen=' + screen.width + 'x' + screen.height'); 
</script> 

</head> 
<body> 

<?php $lol=$_GET['screen']; ?>
<?php echo "SIZE : $lol" ?> 

</body> 
</html> 

And it doesnt works. What i'm doing wrong?

Community
  • 1
  • 1
TRAVA
  • 211
  • 2
  • 12

3 Answers3

0

Probably because register_globals is Off (which is default as of PHP 5 AFAIR). use $_GET['screen'] instead.

register_globals is off by default since PHP 4.2

Also the [img] tag you're printing seems to be kind of BBcode, not HTML. Is that on purpose?

migajek
  • 8,524
  • 15
  • 77
  • 116
0

document.write('script.php?screen=' + screen.width + 'x' + screen.height');
should be replaced with
document.write('<img src="script.php?screen=' + screen.width + 'x' + screen.height'+" />');

migajek
  • 8,524
  • 15
  • 77
  • 116
0

You need at least:

  1. Javascript enabled on the client site (and figure out a nice degrade if it isn't)
  2. A second request (the first request is done and over when javascript is called to action, you cannot get anything from it with the PHP building the page).

A feasible would be to default to a dimension of your choice, use that as a base, and define a function on document.onload to possibly alter your default in javascript alone, unless javascript has already determined the user-agents dimension and you remembered them in a session or similar. When you have determined the dimension your default output may alter.

Wrikken
  • 69,272
  • 8
  • 97
  • 136