help me ...please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

help me ...please

Post by basdog22 »

I have a code like this:

Code: Select all

<?php
if($ie=="ie")
{  //I end the php to do some javascript
 ?>
<script type="javascript">
if (screen.width==800 || screen.height==600)
{
<?php $ie="small"; ?> 
}
</script>
 <?php
}

....
....

?>
what am i doing wrong???

if i am right then if the javascript IF statement is wrong then the $ie will never be "small". But when i try it , it is always "small"

i tried:

document.write and more but it just want work
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

You can't mix PHP with JavaScript like that. PHP runs on the server before the page is sent to the browser. JavaScript runs once the page has been sent to the browser.

If you want to get a variable from JS to PHP you will need to send it via GET (as part of a url) or POST (as part of a form).
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

oops :oops: :oops: :oops: :oops: :oops: :oops: :oops:


Maybe there is another way...

What i want is :

see if the user has: 800x600 resolution and link another stylesheet for him.

If the user has more than 800x600 then link the default stylesheet..

Is there a way to do that???
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

This should work...

Code: Select all

<head>
<script type="text/javascript">

var file = screen.width==800 && screen.height==600 ? "small" : "default";

document.write('<link href="'+file+'.css" type="text/css" rel="stylesheet" />\r\n');

</script>
</head>
I tend to use a similar thing now and again to change the background-color/style of a website depending on the time of day (or night).
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

this is ok but...

i already coded a css switcher in php and it depends on which browser the user uses...So i must either recode the switcher in javascript or find a shorter way...

Thanks Gen-ik :wink:
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

I would always normally suggest to people to use PHP, but for this job I would recommened JS. The main reason being you won't have to bounce people around to different pages just to sort out the CSS.

Here's my JS I use for basic browser/OS detection...

Code: Select all

var o = new Object();

o.u =  navigator.userAgent.toLowerCase();
o.a =  navigator.appName.toLowerCase();
o.av = navigator.appVersion;

o.aol   = o.u.indexOf('aol')!=-1 ? true : false;
o.opera = o.u.indexOf('opera')!=-1 ? true : false;
o.lynx  = o.u.indexOf('lynx')!=-1 ? true : false;
o.ns    = !o.opera && o.a.indexOf('netscape')!=-1 ? true : false;
o.gecko = o.u.indexOf('gecko')!=-1 ? true : false;
o.ie    = !o.opera && o.u.indexOf('msie')!=-1 ? true : false;

o.unix = o.u.indexOf("x11")!=-1 || o.u.indexOf("sunos")!=-1 || o.u.indexOf("linux")!=-1 ? true:false;
o.mac  = o.u.indexOf("mac")!=-1 || o.u.indexOf("ppc")!=-1 ? true:false;
o.win  = o.u.indexOf('win')!=-1 ? true:false;
To check for IE and WIN for example just use something like if(o.ie && o.win){ do something }
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

great :D :D :D :D

BTW what is going on with your avatar????? :?: :?: :?: :?: :?: 8O :P :P :P
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

basdog22 wrote:great :D :D :D :D

BTW what is going on with your avatar????? :?: :?: :?: :?: :?: 8O :P :P :P
Ha. I've made myself one of those (random) avatars ;)
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Gen-ik wrote:
Ha. I've made myself one of those (random) avatars ;)
One of those eh? ;)

-Nay
Post Reply