PHP PHP Script (Use Firefox or Else!)

ReVolver

Moderator
Staff member
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

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

AceHart

Your Friendly Neighborhood Admin
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
Staff member
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

____ ___ ____ __
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

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

DDRtists

ɹoʇɐɹǝpoɯ ɹǝdns
Staff member
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─
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.
  • Ghan Ghan:
    Test!
  • tom_mai78101 tom_mai78101:
    I must be in a test server.
  • tom_mai78101 tom_mai78101:
    Nice, Twitter tweets embedding now works
  • Wizard Wizard:
    Yup.
  • Ghan Ghan:
    Excellent.
  • Ghan Ghan:
    @tom_mai78101 Hello there.
  • Ghan Ghan:
    Tagging works in the chat too.
  • tom_mai78101 tom_mai78101:
    @Ghan Missed it.
  • Wizard Wizard:
    Still fixing things here and there. Added widgets to the portal, will make it match the ones here on the forum index tomorrow.
  • Ghan Ghan:
    The venerable World Editor Tutorials site has been converted to HTTPS at last.
  • jonas jonas:
    cool
  • jonas jonas:
    and I can even edit my messages, nice
  • seph ir oth seph ir oth:
    GENERAL CHIT CHAT, YOU ARE A BOLD ONE
  • Ghan Ghan:
    Hello there
  • The Helper The Helper:
    this new chatbox is great and the forum software update is great too
    +1
  • The Helper The Helper:
    upgrade has fixed forum registration spam problem
  • tom_mai78101 tom_mai78101:
    Something tells me we might be able to customize the chatbox a bit, considering that there's a gap under every message.
  • Wizard Wizard:
    Going to deploy a fix soon, just had to take some time for myself this weekend.
  • Varine Varine:
    Unbelievable. Time for yourself? How dare you!
  • Wizard Wizard:
    xD
  • tom_mai78101 tom_mai78101:
    Hm, it is now harder to type anything on an Android phone. Pressing Backspace or Enter keys will dismiss the Android keyboard for some reasons.
  • tom_mai78101 tom_mai78101:
    Just noticed there's a delay of at least 2 minutes before each post. Guess I can't post Headline News quickly as I used to.
  • tom_mai78101 tom_mai78101:
    As far as I can tell, there are definitely things I need to get accustomed to first.
  • Varine Varine:
    FCC is cracking down recently

    Members online

    No members online now.

    Affiliates

    Hive Workshop
    Top