Do not work a transfer of a variable [duplicate]
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 doe开发者_如何学运维snt works. What i'm doing wrong?
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'+" />');
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?
You need at least:
- Javascript enabled on the client site (and figure out a nice degrade if it isn't)
- 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.
精彩评论