Linking help..
Moderator: General Moderators
-
seeker2921
- Forum Contributor
- Posts: 120
- Joined: Sat Mar 22, 2003 7:10 pm
- Location: Wiesbaden Germany
- Contact:
Linking help..
Hello,
This may be tricky to explain what I want but I will try my best.. I need a page to dectect the users resolution.. I have the script to detect it I just need the php page.. What I want is when index.php is loaded it detects the resolution but instead of it going to a diff page and the url being http://www.domain.com/index_800_600.php it be http://www.domain.com/index.php?res=800_600.. does that make since??
I hope so.. thank you for your help..
This may be tricky to explain what I want but I will try my best.. I need a page to dectect the users resolution.. I have the script to detect it I just need the php page.. What I want is when index.php is loaded it detects the resolution but instead of it going to a diff page and the url being http://www.domain.com/index_800_600.php it be http://www.domain.com/index.php?res=800_600.. does that make since??
I hope so.. thank you for your help..
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
seeker2921
- Forum Contributor
- Posts: 120
- Joined: Sat Mar 22, 2003 7:10 pm
- Location: Wiesbaden Germany
- Contact:
All I have is..
Hello,
The only code I have is the browser detection script written in Javascript
I Haven't even tried to do anything with the php yet.. and thats becuase Im to new to php and I haven't played with it enough yet..
The only code I have is the browser detection script written in Javascript
Code: Select all
<script language="JavaScript1.2">
<!--
if (screen.width==800||screen.height==600)
window.location.replace("/htm/800x600")
else if (screen.width==640||screen.height==480)
window.location.replace("/htm/640x480")
else if (screen.width==1024||screen.height==768)
window.location.replace("/htm/1026x768")
else
window.location.replace("/htm/unknown")
//-->
</script>-
seeker2921
- Forum Contributor
- Posts: 120
- Joined: Sat Mar 22, 2003 7:10 pm
- Location: Wiesbaden Germany
- Contact:
Now that I think about it.. I think I can explain what I want better now..
for example..I have index.php.. and in index.php I have the html for the page.. and then the php code.. in the html it has the resolution script.. and in the script instead of the redirect being to "/htm/600x800" it is "index.php?res=800x600" I understand how to get the script to do that bnut what is the php I need in order to do that?
I hope that explains it better
for example..I have index.php.. and in index.php I have the html for the page.. and then the php code.. in the html it has the resolution script.. and in the script instead of the redirect being to "/htm/600x800" it is "index.php?res=800x600" I understand how to get the script to do that bnut what is the php I need in order to do that?
I hope that explains it better
You don't need PHP - just change the code slightly:
Btw: screen-height and -width will probably not always be exactly 800x600 or 1024x768. Try to approximate the values.
Code: Select all
<script language="JavaScript1.2">
<!--
if (screen.width==800||screen.height==600)
window.location.href="http://www.mydomain.com/index.php?res=800x600")
else if (screen.width==640||screen.height==480)
window.location.href="http://www.mydomain.com/index.php?res=640x480")
else if (screen.width==1024||screen.height==768)
window.location.href="http://www.mydomain.com/index.php?res=1026x768")
else
window.location.href="http://www.mydomain.com/index.php?res=unknown")
//-->
</script>-
seeker2921
- Forum Contributor
- Posts: 120
- Joined: Sat Mar 22, 2003 7:10 pm
- Location: Wiesbaden Germany
- Contact:
seeker: iv been there. it took me quite a while to figure out just how to pull variables using $_GET
but if your just going to have a few simple changes to the html code depending on screen resolution, it really is simpler to just make seperate html pages and have the javascript redirect to those pages. PHP is great if you want to do more dynamic pages.
this will pull the info in the javascript patrikG posted.
you'll need to go thru and define what code you want executed under what conditions. for example:
remember, when the top script finds a match, and goes to the latter function, it only executes whats in that function. so if you have completely different code for each page going to be run for each resolution, you'll have to put it all between the { } of the functions.
and dont forget to put all that together between "<? ?> tags for the start and end of your code.
but if your just going to have a few simple changes to the html code depending on screen resolution, it really is simpler to just make seperate html pages and have the javascript redirect to those pages. PHP is great if you want to do more dynamic pages.
this will pull the info in the javascript patrikG posted.
Code: Select all
if (empty($_GETї'res'])) { //if res is not present or defined run unknown()
unknown();} else { //otherwise figure out whats defined
switch ($_GETї'res']) {
case "800x600": //if res=800x600
800x600(); //run the 800x600() function
break;
case "1024x768": //if res=1024x768
1024x768(); //run the 1024x768() function
break;
case "640x480": //if res=1280x1024
1280x1024(); //run the 1280x1024() function
break;
default: //if res isn't any of those things
unknown(); //run the unknown() function
break;
}
};Code: Select all
function 800x600(){
//put whatever code you want executed for users with
//800x600 resolution here.
}
function 1024x768(){
//for users with 1024x768 desktop resolutions
}
function 640x480(){
//for users with 1280x1024 desktop resolutions
}
function unknown(){
//default code for users with unknown desktop resolutions
}and dont forget to put all that together between "<? ?> tags for the start and end of your code.
-
seeker2921
- Forum Contributor
- Posts: 120
- Joined: Sat Mar 22, 2003 7:10 pm
- Location: Wiesbaden Germany
- Contact:
r337ard.. I think I understand what your saying.. You got it right that I just want diff html pages for each res.. This is what I think your saying to do.. This is a examle page..
And I would just add the html for each diff page just like that correct??
Code: Select all
index.php
<?php
if (empty($_GET['res'])) { //if res is not present or defined run unknown()
unknown();} else { //otherwise figure out whats defined
switch ($_GET['res']) {
case "800x600": //if res=800x600
800x600(); //run the 800x600() function
break;
case "1024x768": //if res=1024x768
1024x768(); //run the 1024x768() function
break;
case "640x480": //if res=1280x1024
1280x1024(); //run the 1280x1024() function
break;
default: //if res isn't any of those things
unknown(); //run the unknown() function
break;
}
};
function 800x600(){
//put whatever code you want executed for users with
//800x600 resolution here.
?>
<hmtl>
<head>
<title>800x600 page</title>
</head>
<body>
<font size="3"><i>This is the 800x600 page....</i></font>
</body>
</html>
}
function 1024x768(){
//for users with 1024x768 desktop resolutions
}
function 640x480(){
//for users with 1280x1024 desktop resolutions
}
function unknown(){
//default code for users with unknown desktop resolutions
}
?>-
seeker2921
- Forum Contributor
- Posts: 120
- Joined: Sat Mar 22, 2003 7:10 pm
- Location: Wiesbaden Germany
- Contact:
i ran the code and got the error too, looks like its words only for functions (im still learning this part too). the easiest way have it print a bunch of html is to make a readfile honestly. i put one in the function below. all it does is read the contents of the file. it makes it easier to edit the pages as well when you do it this way (just a bonus).
then make a 800x600.htm file with whatever code you want in there:
thats the easiest way i can think of for doing the php page. again, if your just going to have html code for each page, your better off just having the javascript open a different html file for each resolution. otherwise all your really doing, is having a script call a script to open a html page.
Code: Select all
<?PHP
if (empty($_GETї'res'])) {
unknown();} else {
switch ($_GETї'res']) {
case "800x600":
res1();
break;
default:
unknown();
break;
}
};
function res1(){
readfile("800x600.htm");
}
function unknown(){
echo "defualt";
}
?>Code: Select all
<hmtl>
<head>
<title>800x600 page</title>
</head>
<body>
<font size="3"><i>This is the 800x600 page....</i></font>
</body>
</html>