getting USER_AGENT Please help me out

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
gegeor
Forum Newbie
Posts: 4
Joined: Wed Jul 09, 2003 6:09 am

getting USER_AGENT Please help me out

Post by gegeor »

Hi all:))
I am building pages for imode cellphones and i wish to have the info regarding specific type of phone in order to load specific images (width height)
the code i am trying to make it work is:

Code: Select all

<?php 
 
$var1 = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)";
$var2 = "portalmmm/2.0 P341i(C10;TB)";

//echo $_SERVER&#1111;'HTTP_USER_AGENT'];

if ($_SERVER&#1111;'HTTP_USER_AGENT'] ='$var1')   &#123;

echo $var1; 
&#125; 

if ($_SERVER&#1111;'HTTP_USER_AGENT'] = '$var2')&#123;

 echo "gegeor: WebHosting";


&#125;

?>
The var1 is the ordinary IE browser and th e var 2 is the cellphone the specific model
What i need is that when the php code detects specific phone model ,then i need to load a specific image. Is that possible.?
So far my code isnt working..(:(
Can someon e please help me out?
Thanks:))
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

it's easy - just remove quotes around the $var1 and $var2 in if condition and use the comparision operator (==) instead of assignment (=), eg. :

Code: Select all

//.....
if ($_SERVER['HTTP_USER_AGENT'] == $var1)   {
   echo $var1;
}
//.....
Besides that, it would be more useful and proper not to test USER_AGENT for exact match, but instead for partial match (.NET version might be different, but it's still IE ;) ).
Post Reply