How can I get the resolution of a browser with PHP?
Posted: Fri Mar 21, 2003 6:54 am
I am having some problems with getting the resolution of a browser.
I don't want to use JavaScript and this became a big problem.
Can anyone help me out?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<html>
<head>
<script type="text/javascript">
function addResolution(oForm)
{
oForm.res.value = screen.width + "x" + screen.height;
return true;
}
</script>
</head>
<body>
<fieldset><legend>forms</legend>
adding resolution right after "creation" of form
<form name="form1" method="POST" action="http://localhost/test.php">
<input type="hidden" name="res" />
<input type="submit" name="url" value="http://where.do.you/wanna/link/today?" />
</form>
<script type="text/javascript">
document.form1.res.value = screen.width + "x" + screen.height;
</script>
adding resolution when form is submitted
<form method="POST" action="http://localhost/test.php" onSubmit="javascript:addResolution(this);" >
<input type="hidden" name="res" />
<input type="submit" name="url" value="http://where.do.you/wanna/link/today?" />
</form>
adding resolution while form is "created"
<form method="POST" action="http://localhost/test.php">
<script type="text/javascript">
document.write('<input type="hidden" name="res" value="' + screen.width + "x" + screen.height + '" />');
</script>
<input type="submit" name="url" value="http://where.do.you/wanna/link/today?" />
</form>
</fieldset>
<fieldset><legend>anchors</legend>
adding resolution right after "creation" of anchor <br />
<a id="a1" href="http://localhost/test.php">http://localhost/test.php</a>
<script type="text/javascript">
document.getElementById("a1").href += "?res=" + screen.width + "x" + screen.height;
</script>
<br />
writing anchor with resolution via document.write <br />
<script type="text/javascript">
document.write('<a href="http://localhost/test.php?res=' + screen.width + "x" + screen.height + '">');
</script>
http://localhost/test.php
</a>
</fieldset>
</body>
</html>Code: Select all
<html>
<body>
<pre><?php print_r($_REQUEST); ?></pre>
<?php
if(isset($_POST['res']))
echo 'POSTed resolution: ', $_POST['res'];
else if(isset($_GET['res']))
echo 'resolution via GET: ', $_GET['res'];
else
echo 'resolution: undefined';
?>
</body>
</html>