PDA

View Full Version : Anyone know the PHP for..



MrCraig
25-07-2007, 02:12 PM
Well basically im trying to do something so that if the word "Mozilla" appears anywhere in the browser, it will add extra content..

But i have no idea how to code it so it will only look for the work mozilla, not the software as a whole if you know what i mean?

I dont know if this will work


<?
$browser = $_SERVER['HTTP_USER_AGENT'];
if($browser==*Mozilla*)
Echo("BlaBlaBlaBlaBla");
?>


Thanks for any help :)

Blob
25-07-2007, 02:25 PM
Ok, mine doesnt work. Sorry

Invent
25-07-2007, 02:26 PM
<?php

if( preg_match( "/mozilla/i", $_SERVER[ "HTTP_USER_AGENT"] ) )
{

echo "Mozzila";

}
elseif ( preg_match( "/msie/i", $_SERVER[ "HTTP_USER_AGENT" ] ) )
{

echo "Internet Explorer";

}

?>

Dentafrice,
25-07-2007, 02:27 PM
mozilla not mozzila :p

MrCraig
25-07-2007, 02:39 PM
Thanks Invent :) +REP to all of you if i dont have to spread..
EDIT: Have to spread..

Luckyrare
25-07-2007, 02:40 PM
Please note quite a number of browsers use the word Mozilla in there agent name. AOL, IE, Firefox, Googlebot - more and more. useragentstring.com

Or are you trying to target Firefox?

I have coded a function that works pretty well or you can use get_browser()




<?php

/* Id: browser.inc.php, Version: 004 */

################################################## #######################
##################### Uploadz Nyx - FIRST WRITE #########################
################ Coded by Danny Milner @ Uploadz.co.uk #################
################################################## #######################

function agent_browser($agent){

if(eregi("Opera/", $agent)){
$browser = "Opera";
}

elseif(eregi("msie", $agent)){
$browser = "Microsoft Internet Explorer";
}

elseif(eregi("firefox/", $agent)){
$browser = "Mozilla Firefox";
}

elseif(eregi("AppleWebKit/", $agent)){
$browser = "Safari";
}

elseif(eregi("Netscape/", $agent)){
$browser = "Netscape";
}

elseif(eregi("LibWWW", $agent)){
$browser = "LibWWW";
}

elseif(eregi("K-Meleon/", $agent)){
$browser = "K-Meleon";
}

elseif(eregi("Konqueror/", $agent)){
$browser = "Konqueror";
}

elseif(eregi("Camino", $agent)){
$browser = "Camino";
}

elseif(eregi("Flock", $agent)){
$browser = "Flock";
}


else{
$browser = "Unknown";
}

return($browser);

}

?>

Dentafrice,
25-07-2007, 02:52 PM
hmm thats a nice function danny :D

Luckyrare
25-07-2007, 02:54 PM
hmm thats a nice function danny :D
Thank you x] <3

Dentafrice,
25-07-2007, 03:00 PM
ok ontopic: why do you need this anyway? :P

off: when will nyx be eready :(

MrCraig
25-07-2007, 03:01 PM
Thanks Danny :) And ye, the message was still showing up for IE users..

and im pretty sure i need to spread first to rep you.

And i need it, because my site has basically no compatability for firefox, and danny, ive added the background colour to most of the pages, but all the orientations are different.

Luckyrare
25-07-2007, 03:06 PM
Thanks Danny :) And ye, the message was still showing up for IE users..

and im pretty sure i need to spread first to rep you.

And i need it, because my site has basically no compatability for firefox, and danny, ive added the background colour to most of the pages, but all the orientations are different.
eeek...

Only time you really should block of a browser is if there is no way you can get it to work - I would get your template recoded before loosing 15% of possible vistors by blocking them off.

MrCraig
25-07-2007, 03:10 PM
Well, it works, But the pages are completely off and all the margins are different etc etc, and im not going to block them off, just put up an advising message that many features may not work, or not work as well as they are supposed to.

Want to hide these adverts? Register an account for free!