SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
-
Nov 5, 2009, 08:11 #1
- Join Date
- Mar 2008
- Location
- United Kingdom
- Posts
- 1,285
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Check browser and platform with PHP?
Hi,
I'm hoping to check if the browser is Safari and the platform is Windows using a PHP if statement.
How do I achieve this?
Thanks for any helpers.
-
Nov 5, 2009, 08:18 #2
- Join Date
- Oct 2009
- Posts
- 1,852
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thats rare combination
For such a single task you can directly parse User-Agent header, which comes into
$_SERVER['HTTP_USER_AGENT'] variable.
For more complicated parsing take a look on get_browser() function.
-
Nov 5, 2009, 09:07 #3
- Join Date
- Apr 2008
- Location
- North-East, UK.
- Posts
- 6,111
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
Good advice.
A quick Google for user-agent string provided this Michael.
PHP Code:<?php
if(false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Windows') && false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Safari'))
{
#a pretty good chance (but not 100%) this is Safari on Windows.
}
?>@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.
-
Nov 5, 2009, 09:11 #4
- Join Date
- Mar 2008
- Location
- United Kingdom
- Posts
- 1,285
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Brilliant, thanks for the links guys.
I've tried running a get_browser function but to no avail.
I think I just need to store the user agent in a variable and then (somehow) search for both safari and windows in that string. It's that somehow bit that's going to win me the car
-
Nov 5, 2009, 09:15 #5
- Join Date
- Mar 2008
- Location
- United Kingdom
- Posts
- 1,285
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Long story. I used litmus and browsercam to check a whole stack of sites I've built and one form on one site has a Safari/Win issue that wasn't there before.
Literally using it just to add a <br /> tag. Is nice!
strpos - that's what I was thinking. Thanks again Anthony.
-
Nov 5, 2009, 12:32 #6
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
Just remember that the USERagent is user configurable and can contain anything your visitor wants. What are you going to do if their useragent says they are running IESafariFirefoxOperaChrome on windowslinuxos/x?
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Nov 5, 2009, 13:47 #7
- Join Date
- Mar 2008
- Location
- United Kingdom
- Posts
- 1,285
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Good call felgall. TBH I'm not too fussed if a user goes to the bother of doing that, it'll only have a slight design impact
What would be the other way, except for UserAgent? Is there one?
-
Nov 5, 2009, 13:48 #8
- Join Date
- Oct 2009
- Posts
- 1,852
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Nope
-
Nov 5, 2009, 13:53 #9
- Join Date
- Mar 2008
- Location
- United Kingdom
- Posts
- 1,285
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Cool.
So worst thing that happens is it looks a little off, for someone who dabbles with their UserAgent. They'll get a kick. Everybody's happy!
Bookmarks