Jump to content

Trying to modify browser sniffer??


gham

Recommended Posts

Hi folks,

 

I'm NOT a PHP coder but, usually, I can fiddle/reverse engineer a script to fit my purposes.  :-\

 

I tried to find a thread here that would allow me to decipher (by example) an open-source "browser sniffer" script (downloaded from Yootheme (dot) com) that notifies the user if his/her version of ie is old and provides links to "upgrade" to a more "contemporary" browser but... alas!... I may be over my head here... I'm hoping someone here might be willing to help.

 

I'm trying to modify the script to, instead of responding to (and displaying a notification dialogue with various browser download links) only ie 6, notify for ANY version of ie so that I can suggest alternative browsers. (I'd like to help users migrate AWAY from ie!)

 

Is it OK for me to post the code here so that someone might suggest the necessary changes?

Link to comment
Share on other sites

<script type="text/javascript">
function detectBrowser(){
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
if ((browser=="Microsoft Internet Explorer") && (version>=6))
  {
  }
else
  {
  alert("This website is best viewed with IEv6.");
  }
}
</script>

 

But thats javascript

Link to comment
Share on other sites

Actually, the function already exists for you.  Yootheme uses the mootools javascript framework that does all of the browser tests for you.  So just use the following:

 

    * Browser.Engine.trident - (boolean) True if the current browser is Internet Explorer (any).

    * Browser.Engine.trident4 - (boolean) True if the current browser is Internet Explorer 6.

    * Browser.Engine.trident5 - (boolean) True if the current browser is Internet Explorer 7.

    * Browser.Engine.gecko - (boolean) True if the current browser is Mozilla/Gecko.

    * Browser.Engine.webkit - (boolean) True if the current browser is Safari/Konqueror.

    * Browser.Engine.webkit419 - (boolean) True if the current browser is Safari2/WebKit before version 419.

    * Browser.Engine.webkit420 - (boolean) True if the current browser is Safari3 (WebKit SVN Build)/WebKit after version 419.

    * Browser.Engine.presto - (boolean) True if the current browser is Opera.

    * Browser.Engine.presto925 - (boolean) True if the current browser is Opera before or equal version 9.25.

    * Browser.Engine.presto950 - (boolean) True if the current browser is Opera major or equal version 9.50.

    * Browser.Engine.name - (string) The name of the engine.

    * Browser.Plugins.Flash.version - (number) The major version of the flash plugin installed.

    * Browser.Plugins.Flash.build - (number) The build version of the flash plugin installed.

 

Link to comment
Share on other sites

Thank you DarkWater and thesaleboat and CroNIX!!! Sorry about being offline for a bit... life's been demanding of late... good to KNOW who da man is!

 

I'm trying to make sense of CroNIX's suggestion/code... but I think I might be missing the point?! I can't figure out where in the Yootheme script (copied below) there's a call to Mootools framework other than drawing the AJAX notification window (ref. line #57).

 

Here's the script that I'm trying to work with (from Yootheme -- obviously written as a module/extension for Joomla! v1.0.X with hooks to a custom back-end admin CP):

 

 

<?php
/**
* YOOiecheck Joomla! Module
*
* @author    yootheme.com
* @copyright Copyright (C) 2008 YOOtheme Ltd. & Co. KG. All rights reserved.
* @license	 GNU/GPL
*/

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

global $mainframe, $mosConfig_live_site;

// init vars
$message     = $params->get('message', '');
$firefox     = $params->get('firefox', '1');
$safari      = $params->get('safari', '1');
$opera       = $params->get('opera', '1');
$ie          = $params->get('ie', '1');
$module_base = $mosConfig_live_site . '/modules/mod_yoo_iecheck/';

// ie browser check
if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
$is_ie7 = strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie 7') !== false;
$is_ie6 = strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'msie 6') !== false;
if (!$is_ie7 && $is_ie6) {
	// is internet explorer 6, check for cookie		
	if (intval(mosGetParam($_COOKIE, 'yooiecheck', 0)) == 1) {
		return;
	}
} else {
	return;
}
} else {
return;
}

?>

<style type="text/css">
CSS omitted for expediency
</style>

<div id="yoo-iecheck">
<div class="close">[ Close ]</div>
<p class="msg"><?php echo $message; ?>
<?php if ($firefox) : ?><a href="http://www.getfirefox.com" target="_blank"><img width="25" height="24" title="Get Firefox" alt="Get Firefox" src="<?php echo $module_base; ?>images/firefox.png" /> Firefox</a><?php endif; ?>
<?php if ($safari) : ?><a class="safari" href="http://www.apple.com/safari/download/" target="_blank"><img width="25" height="24" title="Get Safari" alt="Get Safari" src="<?php echo $module_base; ?>images/safari.png" /> Safari</a><?php endif; ?>
<?php if ($opera) : ?><a class="opera" href="http://www.opera.com/download/" target="_blank"><img width="25" height="24" title="Get Opera" alt="Get Opera" src="<?php echo $module_base; ?>images/opera.png" /> Opera</a><?php endif; ?>
<?php if ($ie) : ?><a class="internetexplorer" href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx" target="_blank"><img width="25" height="24" title="Get latest Internet Explorer" alt="Get latest Internet Explorer" src="<?php echo $module_base; ?>images/ie.png" /> Internet Explorer</a><?php endif; ?>
</p>
</div>

<script type="text/javascript">

if (window.ie6) {
YOOiecheck = new Class({	
	initialize: function(element){
		this.element = $(element);
		this.elementFx = this.element.effect('opacity',{
			duration: 1000
		});
		this.elementFx.start.pass([0,1], this.elementFx).delay(1500);
		var close = $E('div.close', element);
		if (this.element && close) close.addEvent('click', function(){ this.hide(); }.bind(this));
	},

	hide: function(){
		Cookie.set('yooiecheck', '1', {'path': '/'});
		this.elementFx.start(1,0);
	}
});
window.addEvent('domready', function() { new YOOiecheck('yoo-iecheck'); });
}

</script>

 

I thought that I could simply modify line #24-29 (ie browser check) to identify ANY/ALL msie user agents and trigger the "upgrade" message but I'm lost as why, on in line #27 (if (!$is_ie7 && $is_ie6), the if statement includes ie6 AND ie7. I think I'm confused about the variables(?) within the if (array_key_exists... statement: I'm not understanding what's going on there.

 

I may be "denser" (more dense) than anybody realized here! BTW, DarkWater, I have been trying to self-teach myself PHP for awhile now... what's the best way/book/course in your opinion, to "learn the basics of PHP" (besides this venue: "leaching" your knowledge/expertise)?

 

Much thanx for your generosity/help, guys!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.