PHP Script (Use Firefox or Else!)

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
PHP:
<?php
function browser_detection( $which_test ) {
	$browser = '';
	$dom_browser = '';
	$navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';

	if (stristr($navigator_user_agent, "opera")) 
	{
		$browser = 'opera';
		$dom_browser = true;
	}

	elseif (stristr($navigator_user_agent, "msie 4")) 
	{
		$browser = 'msie4'; 
		$dom_browser = false;
	}

	elseif (stristr($navigator_user_agent, "msie")) 
	{
		$browser = 'msie'; 
		$dom_browser = true;
	}

	elseif ((stristr($navigator_user_agent, "konqueror")) || (stristr($navigator_user_agent, "safari"))) 
	{
		$browser = 'safari'; 
		$dom_browser = true;
	}

	elseif (stristr($navigator_user_agent, "gecko")) 
	{
		$browser = 'mozilla';
		$dom_browser = true;
	}
	
	elseif (stristr($navigator_user_agent, "mozilla/4")) 
	{
		$browser = 'ns4';
		$dom_browser = false;
	}
	
	else 
	{
		$dom_browser = false;
		$browser = false;
	}

	if ( $which_test == 'browser' )
	{
		return $browser;
	}
	elseif ( $which_test == 'dom' )
	{
		return $dom_browser;
	}
}

$user_browser = browser_detection('browser');
$link = '<a href="http://www.mozilla.com" target="_blank">http://www.mozilla.com</a>';

if ( $user_browser == 'msie')
{
	echo 'Internet Explorer is not user friendly with this site.';
	}
	if ( $user_browser == 'mozilla')
	{
	echo 'Thanks for using Firefox! You will now be redirected to our site';
	}
	else
	{
	echo '<br/>Try downloading firefox at ' .$link;
	}
	
?>

Note: I did make the functions I got them from Here all credit goes to them I just edit it.

This will check if they are using IE or FF if its IE it wont let them on your site and take them to Mozilla's Site.

Here is a preview http://orctamer.no-ip.org/tdoa/checkbrowser.php
 

mase

____ ___ ____ __
Reaction score
154
Lol, not use FF or else, just don't use IE :p
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,497
Nice, I guess.
Why though would you want to not allow the only standard browser out there?

When was the last time you seen any version 4 browser?


There's clearly way too much copy & paste going on out there...
 

DDRtists

ɹoʇɐɹǝpoɯ ɹǝdns
Reaction score
415
What is that supposed to do? :eek:

You did it the hard way.

PHP:
$url = array(
	'Nintendo Wii' => 'http://nintendo.com',
	'Opera' => 'http://opera.com',
	'Mozilla Firefox' => 'http://firefox.com'
        //add the rest here
	);

function get_browser_name($user_agent)
{
$browsers = array(
    'Nintendo Wii' => '(Nintendo Wii)',
    'Opera' => 'Opera',
    'Mozilla Firefox'=> '(Firebird)|(Firefox)',
    'Galeon' => 'Galeon',
    'Mozilla'=>'Gecko',
    'MyIE'=>'MyIE',
    'Lynx' => 'Lynx',
    'Netscape' => '(Mozilla/4\.75)|(Netscape6)|(Mozilla/4\.08)|(Mozilla/4\.5)|(Mozilla/4\.6)|(Mozilla/4\.79)',
    'Konqueror'=>'Konqueror',
    'SearchBot' => '(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp/cat)|(msnbot)|(ia_archiver)',
    'Internet Explorer 7' => '(MSIE 7\.[0-9]+)',
    'Internet Explorer 6' => '(MSIE 6\.[0-9]+)',
    'Internet Explorer 5' => '(MSIE 5\.[0-9]+)',
    'Internet Explorer 4' => '(MSIE 4\.[0-9]+)',
);

foreach($browsers as $browser=>$pattern)
{
    if (eregi($pattern, $user_agent)) return $browser;
}
    return 'Unknown';
}
 

mase

____ ___ ____ __
Reaction score
154
Lol, DDR both tamer and I tried to use ur script but we just couldn't get it to work for us... I didn't try an array and in_array() so that could be a way.
 

mase

____ ___ ____ __
Reaction score
154
Yea, its based off of Opera though.
 

DDRtists

ɹoʇɐɹǝpoɯ ɹǝdns
Reaction score
415
I see my "Give me a minute to script that" post was deleted. :eek:

PHP:
<?php

$links = array(
	'wii' => array(
		'text' => 'You are using a Wii!',
		'url' => 'http://nintendo.com'
		)
	'opera' => array(
		'text' => 'You are using Opera!',
		'url' => 'http://opera.com'
		)
	'ff' => array(
		'text' => 'You are leet, and use FireFox <3',
		'url' => 'http://firefox.com'
		)
	'galeon' => array(
		'text' => 'I have no idea what Galeon is, but you are using it',
		'url' => 'http://galeon.com'
		)
	'moz' => array(
		'text' => 'You are using Mozilla',
		'url' => 'http://mozilla.com'
		)
	'myie' => array(
		'text' => 'You are using MyIE',
		'url' => 'http://myie.com'
		)
	'lynx' => array(
		'text' => 'You are using Lynx',
		'url' => 'http://lynx.com'
		)
	'ns' => array(
		'text' => 'You are using Netscape',
		'url' => 'http://netscape.com'
		)
	'ie7' => array(
		'text' => 'You are using IE7',
		'url' => 'http://microsoft.com'
		)
	'ie6' => array(
		'text' => 'You are using IE6',
		'url' => 'http://microsoft.com'
		)
	'ie5' => array(
		'text' => 'You are using IE5',
		'url' => 'http://microsoft.com'
		)
	'ie4' => array(
		'text' => 'You are using IE4',
		'url' => 'http://microsoft.com'
		)
);
		
$find = browser($_SERVER['HTTP_USER_AGENT']);

echo $links[$find]['text'].'<br>'.$links[$find]['url'].'<br><br>';;

function browser($user_agent)
{
$browsers = array(
    'wii' => '(Nintendo Wii)',
    'opera' => 'Opera',
    'ff'=> '(Firebird)|(Firefox)',
    'galeon' => 'Galeon',
    'moz'=>'Gecko',
    'myie'=>'MyIE',
    'lynx' => 'Lynx',
    'ns' => '(Mozilla/4\.75)|(Netscape6)|(Mozilla/4\.08)|(Mozilla/4\.5)|(Mozilla/4\.6)|(Mozilla/4\.79)',
    'knoq'=>'Konqueror',
    'bott' => '(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp/cat)|(msnbot)|(ia_archiver)',
    'ie7' => '(MSIE 7\.[0-9]+)',
    'ie6' => '(MSIE 6\.[0-9]+)',
    'ie5' => '(MSIE 5\.[0-9]+)',
    'ie4' => '(MSIE 4\.[0-9]+)',
);

	foreach($browsers as $browser=>$pattern)
	{
		if (eregi($pattern, $user_agent)) return $browser;
	}
		return 'Unknown';
} 

?>

Thats a start. It doesn't work, I think I screwed up the array or something, but I have to go so I'll leave you with that.
 

Hero

─║╣ero─
Reaction score
250
Why not just check for FF instead off all those...I don't know PHP..but I'm pretty sure if you just check for FF browser and then redirect if it is not then you just redirect to FF site
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top