Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
Restrict code in the templates to certain browsers.
Brad
Join Date: Nov 2001
Posts: 4,765

Washington
by Brad Brad is offline 09 Feb 2006

This thread will teach you how to restrict code in the templates to certain browsers.

Before we begin

This method is not a substitute for proper html and css. Also the way we determine the browser the client is using can easily be spoofed, it's not hard to make vBulletin think firefox is really IE for example.

In other words this method should only be used when there is no other way to get the job done.

The good stuff

There is a function within the vBulletin source code call is_browser. With this function we can determine what type of browser the client is using, and which version of the browser the client is using.

In any given template, you can use this code to display a short message to clients that use Internet Explorer:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

We can also display a message based on the version number of Internet Explorer:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

So why is this useful? Well lets say for some odd reason you do not support Internet Explorer 5 or lower on your site and you would like to display a short message to users visiting your site with that browser. Well we can do something like this:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

This conditional would display "mysite.com only supports Internet Explorer 6.0 and higher, please upgrade your browser" in bold to any client running Internet Explorer version 5.5 or lower. Also before anyone brings this up, no it will not display the message to clients using Internet Explorer version 7. In other words the function is coded in such a way that your code is future proof.

Here is a list of browsers supported by the is_browser function. The call sign is on the left (the name you should use in the function call), the browser name that call sign relates to is on the right.

Supported browsers

opera => Opera
ie => Internet Explorer
mozilla => Mozilla and Mozilla based browsers.
firebird => Older versions of Firefox (below)
firefox => Firefox
camino => Camino
konqueror => Konqueror
safari => Safari
webkit => webkit based applications
webtv => Webtv
netscape => Netscape

Last edited by Brad; 28 Jun 2006 at 21:22..
Views: 4085
Reply With Quote
Comments
  #2  
Old 09 Feb 2006, 17:12
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Real name: sabe
nice work brad
__________________
UNDER CONSTRUCTION: Confessionary Hack

Make me a Hack of The Month author: GRPS: Groups Commune
make my hacks, they'll make you famous

unless it's a security concern, please do not pm/im me for support unless you're willing to pay.
Reply With Quote
  #3  
Old 09 Feb 2006, 22:13
Trigunflame's Avatar
Trigunflame Trigunflame is offline
 
Join Date: Aug 2002
Real name: Dusty Burns
Good idea
Reply With Quote
  #4  
Old 09 May 2006, 09:33
rob30UK rob30UK is offline
 
Join Date: Oct 2005
Is there any way to get to the minor version using native VB code?
Reply With Quote
  #5  
Old 09 May 2006, 18:27
SaN-DeeP's Avatar
SaN-DeeP SaN-DeeP is offline
 
Join Date: Jun 2002
There is a function within the vBulletin source code call is_browser. With this function we can determine what type of browser the client is using, and which version of the browser the client is using.
thanks brad
Reply With Quote
  #6  
Old 30 May 2006, 01:22
blawson12 blawson12 is offline
 
Join Date: Nov 2005
Ah, I was wondering how to do this! This helps alot!
Reply With Quote
  #7  
Old 03 Jun 2006, 17:21
Gio~Logist's Avatar
Gio~Logist Gio~Logist is offline
 
Join Date: Jun 2004
Location: San Francisco
Real name: Giovanni Martinez
Ah. I believe this will be very useful:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________

ModernvB.com - vBulletin Mods & Services - ModernvB.com vBulletin 3 Mods - ModernvB.com vBulletin 4 Mods - Hire ModernvB
Full-Time vB Development - If you can think it, we can build it.
Reply With Quote
Reply

Similar Article
Article Author Type Replies Last Post
Restrict [code] and [php] to registered members only Dean C vBulletin 2.x Full Releases 24 21 Nov 2003 18:10



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 23:23.

Layout Options | Width: Wide Color: