Page 1 of 1

Mobile Browser Identification

Posted: Fri May 13, 2011 3:53 pm
by ta2shop
one question! how can i combine this to lines so thei wil work togeder?
for the browser identity, i have a functions.php file witch has the browser name like so:
$pre = $_SERVER['HTTP_USER_AGENT'];
  
if(strpos($pre, "Firefox")!=0)
$navegador = "Firefox";
 
else if(strpos($pre, "AppleWebKit/533.19.4")!=0)
$navegador = "Safari";
 
else if(strpos($pre, "AppleWebKit/534.24")!=0)
$navegador = "Chrome"; 

else if(strpos($pre, "MSIE 9.0")!=0)
$navegador = "Internet Explorer 9";
 
else if(strpos($pre, "MSIE 8.0")!=0)
$navegador = "Internet Explorer 8";

else if(strpos($pre, "MIDP-2.1")!=0)
$navegador = "BlackBerry 8520";

else if(strpos($pre, "AppleWebKit/530.17")!=0)
$navegador = "Samsung Galaxy 3";

else if(strpos($pre, "AppleWebKit/533.1")!=0)
$navegador = "HTC Desire"; 

else if(strpos($pre, "MIDP-2.0")!=0)
$navegador = "Samsung GT-S3550"; 

else
$navegador = "Unknown";
and the index.php file witch displayes everithing like so:
$pre = $_SERVER['HTTP_USER_AGENT'];

if(strpos($pre, "Firefox")!=0)
 echo"<img src='img/firefox.jpg' width='250' height='250' />";
  
else if(strpos($pre, "AppleWebKit/534.24")!=0)
	echo "<img src='img/chrome.jpg' width='250' height='250' />";
	
else if(strpos($pre, "AppleWebKit/533.19.4")!=0)
	echo "<img src='img/safari.jpg' width='250' height='250' />";
	
else if(strpos($pre, "MIDP-2.1")!=0)
	echo "<img src='img/blackberry.JPG' width='150' height='150' />";
	
else if(strpos($pre, "MSIE 8.0")!=0)
	echo "<img src='img/ie.jpg' width='250' height='250' />";
	
else if(strpos($pre, "MSIE 9.0")!=0)
	echo "<img src='img/ie.jpg' width='250' height='250' />";
	
else if(strpos($pre, "AppleWebKit/530.17")!=0)
	echo "<img src='img/samsung.jpg' width='150' height='150' />";
	
else if(strpos($pre, "AppleWebKit/533.1")!=0)
	echo "<img src='img/htc.jpg' width='150' height='150' />";
	
else if(strpos($pre, "MIDP-2.0")!=0)
	echo "<img src='img/samsung.jpg' width='150' height='150' />";
	

else
	echo"Unknown";
how could i get the same functionality but in one file?

Re: Mobile Browser Identification

Posted: Fri May 13, 2011 4:05 pm
by jacek
Not 100% sure what you mean, but you could define the $navigator variable where you output the img tag

Re: Mobile Browser Identification

Posted: Sun May 15, 2011 12:15 pm
by nyo
Can't you put the echos into the function.php file like this:
if(strpos($pre, "Firefox")!=0)
{
   $navegador = "Firefox";
   echo "<img src='img/firefox.jpg' width='250' height='250' />";
}
Or did you ask something else?

Re: Mobile Browser Identification

Posted: Sun May 15, 2011 5:54 pm
by ta2shop
yeh i alrady changed this, it is much more complex now! just forgot to update the code in the first post.

Re: Mobile Browser Identification

Posted: Sun May 15, 2011 8:53 pm
by Tino
Printing output within a function is generally not considered a best practice. It's better to return the output instead, then 'echo' the function.
function do_something() {
    return "I'm doing stuff, wooo!";
}

echo do_something();

Re: Mobile Browser Identification

Posted: Mon May 16, 2011 4:44 am
by nyo
Tino wrote:Printing output within a function is generally not considered a best practice. It's better to return the output instead, then 'echo' the function.
Tino, I guess it is not a function, it is just in functions.php.

ta2shop, maybe we didn't understand what you really want to accomplish...

Re: Mobile Browser Identification

Posted: Mon May 16, 2011 8:36 am
by ta2shop
nailyener wrote:
Tino wrote:Printing output within a function is generally not considered a best practice. It's better to return the output instead, then 'echo' the function.
Tino, I guess it is not a function, it is just in functions.php.

ta2shop, maybe we didn't understand what you really want to accomplish...
it is a browser identification, what did you not understand?

Re: Mobile Browser Identification

Posted: Mon May 16, 2011 8:44 am
by nyo
ta2shop wrote:it is a browser identification, what did you not understand?
I know it is a browser identification, what I did not understand is your last post:
ta2shop wrote:yeh i alrady changed this, it is much more complex now! just forgot to update the code in the first post.
So, everything is ok now?

Re: Mobile Browser Identification

Posted: Mon May 16, 2011 9:18 am
by ta2shop
nailyener wrote:
ta2shop wrote:it is a browser identification, what did you not understand?
I know it is a browser identification, what I did not understand is your last post:
ta2shop wrote:yeh i alrady changed this, it is much more complex now! just forgot to update the code in the first post.
So, everything is ok now?
this last post is totaly irelevant, i already said that the problem is fixed! forget about this post, focus on the next one!

Re: Mobile Browser Identification

Posted: Mon May 16, 2011 9:22 am
by jacek
ta2shop wrote:this last post is totaly irelevant, i already said that the problem is fixed! forget about this post, focus on the next one!
Since this is apparently just people being confused, locked.

PM me if you want it un-locked :)