I wish to display a block if user is using any version of Firefox web browser.
Please give the required php code. Also mention changes for any version of chrome web browser.

Comments

lm_omar’s picture

hi
i think this link can help you:
http://php.net/manual/fr/function.get-browser.php

tashicoder’s picture

Hi,
Please go to that specific block configure page and in "Page specific visibility settings" section of the block configure , select the 3rd option which says "Show if the following PHP code returns TRUE (PHP-mode, experts only)."
And
Paste this code (<?php ?> should be included too).

$userAgent = $_SERVER['HTTP_USER_AGENT'];
if(!preg_match('/Firefox/i',$userAgent)){
	return FALSE;
}
return TRUE;

Thanks

jaypan’s picture

Changing this line:

if(!preg_match('/Firefox/i',$userAgent)){

To this:

if(stripos($userAgent, 'Firefox') === FALSE){

Is a little less resource intensive. Regex is best saved for searching for patterns, rather than simple strings.

Edit: Actually looking at the whole thing, you could rewrite it like this:

$userAgent = $_SERVER['HTTP_USER_AGENT'];
return (stripos($userAgent, 'Firefox') !== FALSE);

Contact me to contract me for D7 -> D10/11 migrations.

zeroagain’s picture

It works!