Page 1 of 1

getting USER_AGENT Please help me out

Posted: Tue Apr 20, 2004 2:17 pm
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:))

Posted: Wed Apr 21, 2004 1:26 pm
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 ;) ).