We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Browser Sniff

Development and Programming

grantmx's avatar
grantmx
1,439 posts
16 years ago
grantmx's avatar grantmx

Using the same exact code:

{exp:browser_sniff}
{if browser_name=="saf"}
<link rel="stylesheet" type="text/css" media="all" href="{stylesheet=include/safari}" />
{/if}
{/exp:browser_sniff}

It shows the stylesheet in the code in FF3 on XP. Am I behind on the version? Running v1.2.

       
eexperience's avatar
eexperience
56 posts
16 years ago
eexperience's avatar eexperience
It shows the stylesheet in the code in FF3 on XP. Am I behind on the version? Running v1.2.

Have you checked the output for both browsers with this code:

{exp:browser_sniff}
Browser name: {browser_name}

Browser version: {browser_version}
{/exp:browser_sniff}
       
grantmx's avatar
grantmx
1,439 posts
16 years ago
grantmx's avatar grantmx

No, but how would that relate to the issue?

       
Matt Weinberg's avatar
Matt Weinberg
489 posts
16 years ago
Matt Weinberg's avatar Matt Weinberg

It would let you more easily see where the glitch is if you knew how the plugin was reporting both browsers.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

Using the same exact code:
{exp:browser_sniff}
{if browser_name=="saf"}
<link rel="stylesheet" type="text/css" media="all" href="{stylesheet=include/safari}" />
{/if}
{/exp:browser_sniff}
It shows the stylesheet in the code in FF3 on XP. Am I behind on the version? Running v1.2.

Trying your code with Firefox 3 on Windows XP I was unable to replicate the effect you described. That is, the result was as expected - no output.

The issue is not somehow connected with version 1.2 because all versions of Browser Sniff plugin use exactly the same code for browser recognition.

       
eexperience's avatar
eexperience
56 posts
16 years ago
eexperience's avatar eexperience

Is it possible that your template code is cached and that’s the reason why you get the same results for both browsers?

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas
Is it possible that your template code is cached and that’s the reason why you get the same results for both browsers?

That should not be the reason.

Browser Sniff plugin recognizes which browser is used by parsing $_SERVER[‘HTTP_USER_AGENT’] variable. Plugin outputs {browser_name} as “saf” in case $_SERVER[‘HTTP_USER_AGENT’] variable converted to lowercase contains substring “safari” and it outputs {browser_name} as “moz” in case $_SERVER[‘HTTP_USER_AGENT’] variable converted to lowercase contains substring “gecko”.

Here is what $_SERVER[‘HTTP_USER_AGENT’] variable outputs in case browser is Firefox 3 on Vista:

Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1

Here is what $_SERVER[‘HTTP_USER_AGENT’] variable outputs in case browser is Firefox 3 on XP:

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1

As you can see there is no substring “safari”. This is the reason why the code

{exp:browser_sniff}
{if browser_name=="saf"}
<link rel="stylesheet" type="text/css" media="all" href="{stylesheet=include/safari}" />
{/if}
{/exp:browser_sniff}

outputs nothing, as it should, both for Firefox 3 on Vista and on XP.

       
grantmx's avatar
grantmx
1,439 posts
16 years ago
grantmx's avatar grantmx

Hmmm… Interesting. Going to have to look in to why it’s still showing for me. In retrospect, I have it in an embed, so it may be EE parsing order between the template, embed, plug-in and the conditional statement.

       
dwex's avatar
dwex
94 posts
16 years ago
dwex's avatar dwex

Have you thought about extending this to support mobile browser sniffing? I’ve found a gazillion different chunks of PHP that purport to figure out whether the user’s on a mobile or not so they can be redirected to the right pages and/or styled differently. That would be a useful addition.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas
Have you thought about extending this to support mobile browser sniffing? I’ve found a gazillion different chunks of PHP that purport to figure out whether the user’s on a mobile or not so they can be redirected to the right pages and/or styled differently. That would be a useful addition.

Currently Browser Sniff plugin is quite weak. It recognizes several most known browsers and that’s all.

It would be good to extent its capabilities. One possible solution would be to base Browser Sniff plugin on CodeIgniter’s User Agent class.

Unfortunately as yet I have no experience in CodeIgniter’s framework. I will consider this when ExpressionEngine 2.0 based on CodeIgniter will be released and when I will upgrade my plugins to be compatible with it.

       
dwex's avatar
dwex
94 posts
16 years ago
dwex's avatar dwex

Heh. I see what you mean. That would make things much simpler 😊

       
atelier2's avatar
atelier2
181 posts
16 years ago
atelier2's avatar atelier2

Fantastic usefull plug-in. This saves lot’s of work. Thanks!!

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

I released version 1.3 of Browser Sniff plugin.

In this release a basic OS detection was added. In order to output OS you should use {os} variable.

Possible values of {os} variable are: win (windows), mac (Macintosh), linux (Linux), other (other OS).

       
Adam Khan's avatar
Adam Khan
315 posts
15 years ago
Adam Khan's avatar Adam Khan

Thanks, just what I needed!

       
MarkTechArc72's avatar
MarkTechArc72
52 posts
15 years ago
MarkTechArc72's avatar MarkTechArc72

Laisvunas,

Thanks for this plugin, it has helped me to gain compatibility between browsers really well. Great piece of work and thank you!

Appreciate it.

Cheers, Mark.

       
1 2 3 4

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.