It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

browser check

Moderator: Malcolm

browser check

Postby Phate on Sat Mar 25, 2006 12:55 am

I need a php code that will check what browser a user is using. Then, if it is IE, i want it to display text.
Anyone help me out??
Web-Developing since '03
Image
User avatar
Phate
500+ Club
 
Posts: 826
Joined: Sun Nov 21, 2004 4:12 am
Location: 127.0.0.1

Postby johneva on Sat Mar 25, 2006 9:12 am

How did it you want it to work though cos you can just use.
Code: Select all
<!--[if !IE]> <-->
This content will only display if run in any browser except IE.
<!--> <![endif]-->


Or did you want it to call for another file that contains the content if it was not
IE?

Then if you want to display something in IE only you can use pretty much the same thing.

Code: Select all
<!--[if !IE]>
This content will only display in IE.
<![endif]-->


You can also add the version number to these tags so it will only work in certain versions of IE.

Code: Select all
<!--[if !IE 6]>
This content will only display in IE6.
<![endif]-->
Image
Only God Can Judge Me.
User avatar
johneva
500+ Club
 
Posts: 565
Joined: Sat Oct 29, 2005 1:16 pm
Location: Stafford, England

Postby webmaster on Sat Mar 25, 2006 1:51 pm

Here's it in PHP:

[php]<?php

if (preg_match('/IE/', $_SERVER['HTTP_USER_AGENT']) && (preg_match('/Opera/', $_SERVER['HTTP_USER_AGENT']))) {
echo "You are using Opera";
} elseif (preg_match('/IE/', $_SERVER['HTTP_USER_AGENT'])) {
echo "You are using IE";
}

?>[/php]
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Postby Phate on Sun Mar 26, 2006 12:44 am

What I want it to do, is check to see what browser the person is using. If it is not firefox, i want it to say, "This site is best viewed in Mozilla Firefox" (with a link)
Web-Developing since '03
Image
User avatar
Phate
500+ Club
 
Posts: 826
Joined: Sun Nov 21, 2004 4:12 am
Location: 127.0.0.1

Postby johneva on Sun Mar 26, 2006 9:27 am

I would use Webmasters way then as the way I showed can only recogise IE or not, so you can only show/hide from IE.

Where as using PHP to check, you can check for firefox then show or hide.
Image
Only God Can Judge Me.
User avatar
johneva
500+ Club
 
Posts: 565
Joined: Sat Oct 29, 2005 1:16 pm
Location: Stafford, England

Postby webmaster on Sun Mar 26, 2006 11:14 am

Phate wrote:What I want it to do, is check to see what browser the person is using. If it is not firefox, i want it to say, "This site is best viewed in Mozilla Firefox" (with a link)


[php]<?php

if (preg_match('/IE/', $_SERVER['HTTP_USER_AGENT']) || (preg_match('/Opera/', $_SERVER['HTTP_USER_AGENT']))) {
echo "This site is best viewed in <a href="http://www.mozilla.org">Mozilla Firefox</a>";
}

?>[/php]
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden


Who is online

Users browsing this forum: No registered users and 1 guest