the_idiot
07-19-2003, 12:43 PM
I would like to set a page that prints a header based on the client's screen resolution. I am attempting to do this with some JavaScript on the index.htm page that retrieves the resolution information and passes it, via a query string, to a php page that uses selection to require() one of two headers depending on the query string variable's value.
*****Script to get resolution*****
<script language="JavaScript" type="text/javascript">
function choose_header() {
if (window.screen.width==800 && window.screen.height==600) {
window.location.href="/mc/dev/hometest.php?sr=1"
} else {
window.location.href="/mc/dev/hometest.php?sr=2"
}
}
</script>
*****************************
******Script to print header******
<?php
function print_header($res) {
if ($res == 1) {
require('header_800.inc');
} elseif (res == 2) {
require('header_1024.inc');
} else {
echo '</head>'."/n".
'<body>'."/n".
"<h1>res: $res</h1>";
}
$reso = $_GET['sr'];
if (isset($reso)) {
print_header($reso);
} else {
echo '</head><body><h1>$reso is not set.</h1>';
}
?>
*****************************
The problem is that the server does not render the php script at all. I set up a simple php page with a single require() statement which printed one of the aforementioned headers:
<?php
require('header_1024.inc');
?>
This worked just fine.
I also wrote a script to try and test values of the query string variable:
<?php
$reso = $_GET['sr'];
if (empty($reso)) {
echo '<h1>$reso is empty.</h1>';
} elseif (isset($reso)) {
echo '<h1>$reso is'.$reso.'</h1>'
}
?>
This script was not rendered either.
Examples can be seen using the following links:
hometest.php (http://www.solas.cc/mc/dev/) (redirect via index.htm: query string value passed)
hometest.php (http://www.solas.cc/mc/dev/hometest.php) (direct link: no query string value passed)
myphp.php (http://www.solas.cc/mc/dev/myphp.php) (test page for include file and php engine)
foo.php (http://www.solas.cc/mc/dev/foo.php) (script to test query string values: no values passed)
Questions........
Have I passed the value from the JavaScript correctly?
Have I retrieved the variable correctly in the php scripts?
Why aren't hometest.php and foo.php rendered while myphp.php is?
Any help is greatly appreciated.
*****Script to get resolution*****
<script language="JavaScript" type="text/javascript">
function choose_header() {
if (window.screen.width==800 && window.screen.height==600) {
window.location.href="/mc/dev/hometest.php?sr=1"
} else {
window.location.href="/mc/dev/hometest.php?sr=2"
}
}
</script>
*****************************
******Script to print header******
<?php
function print_header($res) {
if ($res == 1) {
require('header_800.inc');
} elseif (res == 2) {
require('header_1024.inc');
} else {
echo '</head>'."/n".
'<body>'."/n".
"<h1>res: $res</h1>";
}
$reso = $_GET['sr'];
if (isset($reso)) {
print_header($reso);
} else {
echo '</head><body><h1>$reso is not set.</h1>';
}
?>
*****************************
The problem is that the server does not render the php script at all. I set up a simple php page with a single require() statement which printed one of the aforementioned headers:
<?php
require('header_1024.inc');
?>
This worked just fine.
I also wrote a script to try and test values of the query string variable:
<?php
$reso = $_GET['sr'];
if (empty($reso)) {
echo '<h1>$reso is empty.</h1>';
} elseif (isset($reso)) {
echo '<h1>$reso is'.$reso.'</h1>'
}
?>
This script was not rendered either.
Examples can be seen using the following links:
hometest.php (http://www.solas.cc/mc/dev/) (redirect via index.htm: query string value passed)
hometest.php (http://www.solas.cc/mc/dev/hometest.php) (direct link: no query string value passed)
myphp.php (http://www.solas.cc/mc/dev/myphp.php) (test page for include file and php engine)
foo.php (http://www.solas.cc/mc/dev/foo.php) (script to test query string values: no values passed)
Questions........
Have I passed the value from the JavaScript correctly?
Have I retrieved the variable correctly in the php scripts?
Why aren't hometest.php and foo.php rendered while myphp.php is?
Any help is greatly appreciated.