9 Replies - 959 Views - Last Post: 01 February 2009 - 02:09 PM Rate Topic: -----

#1 ChrissehB   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 01-February 09

PHP Help :S

Posted 01 February 2009 - 07:03 AM

OK really need help! I'm trying to make a script which gets the users screen resolution to display a certain code but it wont work and i really have no idea why :S
<?
$sw = " <script> document.write(screen.width) </script> ";
$sh = " <script> document.write(screen.height) </script> ";
if($sw == '1024' && $sh == '768'){ include ("1024x768.html"); }
elseif($sw == '1280' && $sh == '800'){ include ("1280x800.html"); }
elseif($sw == '1280' && $sh == '1024'){include ("1280x1024.html"); }
elseif($sw == '1600' && $sh == '1200'){ include ("1600x1200.html"); }
else { ?><script language="javascript" type="text/javascript">
alert('Sorry but your screen resolution, is currently not supported. Your navigation will be standard.');
</script>
<? 
}
?>


Can anyone help me work out how to use this?

Is This A Good Question/Topic? 0
  • +

Replies To: PHP Help :S

#2 CTphpnwb   User is online

  • D.I.C Lover
  • member icon

Reputation: 3800
  • View blog
  • Posts: 13,783
  • Joined: 08-August 08

Re: PHP Help :S

Posted 01 February 2009 - 08:08 AM

I believe you want to declare the language and echo it:
$sw = '<script language="Javascript" type="text/Javascript" > document.write(screen.width) </script>';
$sh = '<script language="Javascript" type="text/Javascript" > document.write(screen.height) </script>';
echo $sw.$sh;


Actually, I don't even think that will work, but it's close.

This post has been edited by CTphpnwb: 01 February 2009 - 08:09 AM

Was This Post Helpful? 0
  • +
  • -

#3 Auzzie   User is offline

  • D.I.C Addict
  • member icon

Reputation: 43
  • View blog
  • Posts: 573
  • Joined: 20-January 09

Re: PHP Help :S

Posted 01 February 2009 - 08:18 AM

i didnt think the php was needed as document.write already prints to page :S
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb   User is online

  • D.I.C Lover
  • member icon

Reputation: 3800
  • View blog
  • Posts: 13,783
  • Joined: 08-August 08

Re: PHP Help :S

Posted 01 February 2009 - 08:26 AM

But the way he has it, document.write is just a string. I never gets executed.
Was This Post Helpful? 0
  • +
  • -

#5 ChrissehB   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 01-February 09

Re: PHP Help :S

Posted 01 February 2009 - 08:38 AM

Ok no success =/
I changed the code to this:
  <?
  error_reporting(E_ALL ^ E_NOTICE);
$screen_res = "<script>document.write(screen.width)</script><script>document.write(screen.height)</script>";
echo ("$screen_res");
if($screen_res == "1024768"){ include ("1024x768.html"); }
elseif($screen_res == "1280800"){ include ("1280x1024.html"); }
elseif($screen_res == "1280800"){include ("1280x1024.html"); }
elseif($screen_res == "16001200"){ include ("1600x1200.html"); }
else { ?><script language="javascript" type="text/javascript">
alert('Sorry but your screen resolution, is currently not supported. Your navigation will be standard.');
</script>
<?
}
?>

I added the echo in to see what it was displaying and it showed 1280800 but still didn't include the file?

Any more help please?
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb   User is online

  • D.I.C Lover
  • member icon

Reputation: 3800
  • View blog
  • Posts: 13,783
  • Joined: 08-August 08

Re: PHP Help :S

Posted 01 February 2009 - 08:42 AM

And what language is this?

$screen_res = "<script>document.write(screen.width)</script><script>document.write(screen.height)</script>";
Was This Post Helpful? 0
  • +
  • -

#7 ChrissehB   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 01-February 09

Re: PHP Help :S

Posted 01 February 2009 - 09:15 AM

Changed it to:
  <?
  error_reporting(E_ALL ^ E_NOTICE);
$screen_res = "<script language=\"javascript\" type=\"text/javascript\">document.write(screen.width)</script><script language=\"javascript\" type=\"text/javascript\">document.write(screen.height)</script>";
echo ("$screen_res");
if( $screen_res == "1024768" ) { include ("1024x768.html"); }
elseif( $screen_res == "1280800" ) { include ("1280x1024.html"); }
elseif( $screen_res == "1280800" ) {include ("1280x1024.html"); }
elseif( $screen_res == "16001200" ) { include ("1600x1200.html"); }
else { ?><script language="javascript" type="text/javascript">
alert('Sorry but your screen resolution, is currently not supported. Your navigation will be standard.');
</script>
<?
}
?>

But still the same .'


EDIT: Tried this aswell but still same -.- :
  <?
  error_reporting(E_ALL ^ E_NOTICE);
$screen_res = '<script language="javascript" type="text/javascript">document.write(screen.width)</script><script language="javascript" type="text/javascript">document.write(screen.height)</script>';
echo ("$screen_res");
if( $screen_res == "1024768" ) { include ("1024x768.html"); }
elseif( $screen_res == "1280800" ) { include ("1280x1024.html"); }
elseif( $screen_res == "1280800" ) {include ("1280x1024.html"); }
elseif( $screen_res == "16001200" ) { include ("1600x1200.html"); }
else { ?><script language="javascript" type="text/javascript">
alert('Sorry but your screen resolution, is currently not supported. Your navigation will be standard.');
</script>
<?
}
?>

This post has been edited by ChrissehB: 01 February 2009 - 09:21 AM

Was This Post Helpful? 0
  • +
  • -

#8 CTphpnwb   User is online

  • D.I.C Lover
  • member icon

Reputation: 3800
  • View blog
  • Posts: 13,783
  • Joined: 08-August 08

Re: PHP Help :S

Posted 01 February 2009 - 10:10 AM

Oops! I didn't notice earlier, but your javascript merely writes to the html output and you need it to communicate with php. You need to use ajax. Sorry, but I'm not good with ajax. I'll try to look into it.
Was This Post Helpful? 0
  • +
  • -

#9 ChrissehB   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 01-February 09

Re: PHP Help :S

Posted 01 February 2009 - 10:28 AM

OK! Thanks for all your help but i've found a different solution!
I used this code in the head:
<?
if(isset($_COOKIE["users_resolution"])){
	$res = $_COOKIE["users_resolution"];
	}
else //means cookie is not found set it using Javascript
{
?>
<script language="javascript">
<!--
writeCookie();

function writeCookie() 
{
 var today = new Date();
 var the_date = new Date("December 31, 2023");
 var the_cookie_date = the_date.toGMTString();
 var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
 var the_cookie = the_cookie + ";expires=" + the_cookie_date;
 document.cookie=the_cookie
	 
 location = 'index.php';
}
//-->
</script>
<?
}
?>

And this to display:
  <?
  error_reporting(E_ALL ^ E_NOTICE);
if( $res == "1024x768" ) { include ("1024x768.html"); }
elseif( $res == "1280x800" ) { include ("1280x800.html"); }
elseif( $res == "1280x1024" ) {include ("1280x1024.html"); }
elseif( $res == "1600x1200" ) { include ("1600x1200.html"); }
?>



I got the code from PHPBuddy.com but it was just an endless loop so I changed the cookie bit from:
$HTTP_COOKIE_VARS["users_resolution"]

To simply:
$_COOKIE["user_resolution"]

And it stopped refreshing in an endless loop and worked ;o

Thanks anyway everybody!
Was This Post Helpful? 0
  • +
  • -

#10 Auzzie   User is offline

  • D.I.C Addict
  • member icon

Reputation: 43
  • View blog
  • Posts: 573
  • Joined: 20-January 09

Re: PHP Help :S

Posted 01 February 2009 - 02:09 PM

Glad you managed to get it fixed and following this has helped me with a problem or two of mine for something similar
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1