Page 1 of 1

Linking help..

Posted: Tue May 06, 2003 12:38 am
by seeker2921
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..

Posted: Tue May 06, 2003 3:47 am
by twigletmac
Could you show us the code you have so far?

Mac

All I have is..

Posted: Tue May 06, 2003 4:42 pm
by seeker2921
Hello,

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>
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..

Posted: Tue May 06, 2003 4:48 pm
by seeker2921
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

Posted: Tue May 06, 2003 5:40 pm
by patrikG
You don't need PHP - just change the code slightly:

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>
Btw: screen-height and -width will probably not always be exactly 800x600 or 1024x768. Try to approximate the values.

Posted: Tue May 06, 2003 5:48 pm
by seeker2921
Ok.. I undertsand that that I would need to do that.. But if I just link to index.php?res=600x800 Its isnt going to do anything.. I dont know how to make index.php understand what to do with ?res=600x800??

Posted: Tue May 06, 2003 5:53 pm
by patrikG

Posted: Tue May 06, 2003 6:40 pm
by r337ard
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.

Code: Select all

if (empty($_GET&#1111;'res'])) &#123;  //if res is not present or defined run unknown()
unknown();&#125; else &#123;            //otherwise figure out whats defined

switch ($_GET&#1111;'res']) &#123;
	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;           
&#125;

&#125;;
you'll need to go thru and define what code you want executed under what conditions. for example:

Code: Select all

function 800x600()&#123;
        //put whatever code you want executed for users with 
        //800x600 resolution here.
&#125;
function 1024x768()&#123;
        //for users with 1024x768 desktop resolutions
&#125;
function 640x480()&#123;
        //for users with 1280x1024 desktop resolutions
&#125;
function unknown()&#123;
        //default code for users with unknown desktop resolutions
&#125;
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.

Posted: Tue May 06, 2003 6:59 pm
by seeker2921
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..

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 
} 



?>
And I would just add the html for each diff page just like that correct??

Posted: Tue May 06, 2003 10:18 pm
by seeker2921
I used the code I said above and this is the error that I got..

Parse error: parse error, unexpected T_STRING in /home/alienweb/public_html/index.php on line 7

any ideas??

Posted: Tue May 06, 2003 10:20 pm
by r337ard
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).

Code: Select all

<?PHP

if (empty($_GET&#1111;'res'])) &#123;  
unknown();&#125; else &#123;          

switch ($_GET&#1111;'res']) &#123;
   case "800x600":   
      res1();   
      break;
   default:            
      unknown();   
      break;           
&#125;

&#125;;

function res1()&#123;
	readfile("800x600.htm");
&#125;

function unknown()&#123;
	echo "defualt";
&#125;
?>
then make a 800x600.htm file with whatever code you want in there:

Code: Select all

<hmtl>
<head>
<title>800x600 page</title>
</head>
<body>
<font size="3"><i>This is the 800x600 page....</i></font>
</body>
</html>
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.