Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,006 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,351 people online right now. Registration is fast and FREE... Join Now!




Browser Detection

 
Reply to this topicStart new topic

Browser Detection

musya
12 Mar, 2008 - 07:25 AM
Post #1

D.I.C Regular
Group Icon

Joined: 25 Apr, 2007
Posts: 291



Thanked: 1 times
Dream Kudos: 50
My Contributions
Hello, I am working on a website template to work with Joomla, but the problem I have been having is with the CSS so I decided to have 3 different ones,
1. IE
2. FF
3. SF

But I am not the best at php and all of the scripts I found for browser detection wouldnt work, so I know there is a policy here about show work first then we'll help you, well I dont know what to show other than the template but I'm at work and I cant do that, plus that would have nothing to do with this I wouldnt think.
So if you guys can help point me in the right direction that would be greatly appreciated.

Thank you,
Musya
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Browser Detection
12 Mar, 2008 - 08:04 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 11 times
My Contributions
Maybe this article can help
User is offlineProfile CardPM
+Quote Post

musya
RE: Browser Detection
12 Mar, 2008 - 08:28 AM
Post #3

D.I.C Regular
Group Icon

Joined: 25 Apr, 2007
Posts: 291



Thanked: 1 times
Dream Kudos: 50
My Contributions
QUOTE(1lacca @ 12 Mar, 2008 - 09:04 AM) *


Thanks, I appreciate it.
User is offlineProfile CardPM
+Quote Post

spearfish
RE: Browser Detection
12 Mar, 2008 - 09:04 AM
Post #4

Monkey in Training
Group Icon

Joined: 10 Mar, 2008
Posts: 746



Thanked: 2 times
Dream Kudos: 225
My Contributions
You may also be interested in conditional comments. You can input special instructions for IE.

<!--[if IE>
<!-- Special instructions here -->
<![endif]-->

You can also target different versions of IE, or enable instructions if it's not IE. This is generally better than a script / coding browser detection, since in my experience all major browsers work like Firefox except for IE --- and that said, 95% of the market uses IE or FF

http://msdn2.microsoft.com/en-us/library/ms537512.aspx
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Browser Detection
12 Mar, 2008 - 09:14 AM
Post #5

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 11 times
My Contributions
True, and there are other CSS hacks to aim special browsers, but as I saw nowadays this practice is not encouraged (however it can come handy, that's for sure) .
User is offlineProfile CardPM
+Quote Post

spearfish
RE: Browser Detection
12 Mar, 2008 - 09:26 AM
Post #6

Monkey in Training
Group Icon

Joined: 10 Mar, 2008
Posts: 746



Thanked: 2 times
Dream Kudos: 225
My Contributions
QUOTE(1lacca @ 12 Mar, 2008 - 10:14 AM) *

True, and there are other CSS hacks to aim special browsers, but as I saw nowadays this practice is not encouraged (however it can come handy, that's for sure) .


The most famous of these would probably be the holly hack, which plays off of IE's insistance that there's an element above "html"....
CODE

* html {.....


which takes priority in the cascade because of the star in front.

But that doesn't work in IE7 and probably not 8
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Browser Detection
13 Mar, 2008 - 04:58 AM
Post #7

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,906



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
There's a much better way to detect browsers.
I use it all the time.
Follow these steps:
  • First, download a copy of browscap.ini file from the PHP website.
  • Place it into your PHP directory.
  • Add the following line to your php.ini file:
    [browscap]
    browscap = "<path>/browscap.ini"
  • Restart your Server.
  • Use the get_browser() function to get Browser details.
Here's an example of the get_browser() function taken from the PHP documentation:
php

<?php
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

$browser = get_browser(null, true);
print_r($browser);
?>

The above example will output something similar to:
QUOTE
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3

Array
(
[browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$
[browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*
[parent] => Firefox 0.9
[platform] => WinXP
[browser] => Firefox
[version] => 0.9
[majorver] => 0
[minorver] => 9
[css] => 2
[frames] => 1
[iframes] => 1
[tables] => 1
[cookies] => 1
[backgroundsounds] =>
[vbscript] =>
[javascript] => 1
[javaapplets] => 1
[activexcontrols] =>
[cdf] =>
[aol] =>
[beta] => 1
[win16] =>
[crawler] =>
[stripper] =>
[wap] =>
[netclr] =>
)

User is offlineProfile CardPM
+Quote Post

spearfish
RE: Browser Detection
13 Mar, 2008 - 05:27 AM
Post #8

Monkey in Training
Group Icon

Joined: 10 Mar, 2008
Posts: 746



Thanked: 2 times
Dream Kudos: 225
My Contributions
^^^What he said
User is offlineProfile CardPM
+Quote Post

thehat
RE: Browser Detection
13 Mar, 2008 - 05:35 AM
Post #9

D.I.C Head
Group Icon

Joined: 28 Feb, 2008
Posts: 217


Dream Kudos: 100
My Contributions
As long as you have access to the php folder. Might be a problem for shared hosting.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 12:50PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month