2 Replies - 3767 Views - Last Post: 21 August 2010 - 09:46 AM Rate Topic: -----

#1 Anandmahalakshmi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-December 08

How can we get the browser properties using php?

Posted 20 August 2010 - 04:41 AM

How can we get the browser properties using php?
Is This A Good Question/Topic? 0
  • +

Replies To: How can we get the browser properties using php?

#2 mahcuz  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 143
  • View blog
  • Posts: 213
  • Joined: 03-June 10

Re: How can we get the browser properties using php?

Posted 20 August 2010 - 05:23 AM

What are browser properties? Also, you should understand that the browser and PHP are 2 completely separate entities, they don't speak to each other, nor do they have any knowledge of one another. Your Browser talks to The Server which talks to PHP which talks back to The Server which talks back to Your Browser. You can often obtain some limited information about the visiting client via the $_SERVER['HTTP_USER_AGENT'] variable - don't rely on it, though.

This post has been edited by mahcuz: 20 August 2010 - 05:26 AM

Was This Post Helpful? 3
  • +
  • -

#3 KingCuddles  Icon User is offline

  • D.I.C Regular

Reputation: 176
  • View blog
  • Posts: 496
  • Joined: 20-December 08

Re: How can we get the browser properties using php?

Posted 21 August 2010 - 09:46 AM

Here is a basic browser identification script I wrote, although please remember that as mahcuz has already pointed out, it is not 100% accurate, and is very easy to manipulate.

function browsertype()
{
//Create a variable which gets the UserAgent String
$ua = $_SERVER['HTTP_USER_AGENT'];
$browser = ""

//Netscape
if (strpos($ua,'Netscape'))
{
$browser = "Netscape";
}
//Chrome
else if (strpos($ua,'Chrome'))
{
$browser = "Google Chrome";
}
//Flock
else if (strpos($ua,'Flock'))
{
$browser = "Flock";
}
//Firefox
else if (strpos($ua,'Firefox'))
{
$browser = "Mozilla Firefox";
}
//Opera
else if (strpos($ua,'Opera') == false)
{
$browser = "Opera";
}
//Internet Explorer
else if (strpos($ua,'MSIE'))
{
$browser = "Microsoft Internet Explorer";
}
//Safari
else if (strpos($ua,'Safari'))
{
$browser = "Safari";
}
else 
{
$browser = "Unrecognised Browser";
}
return $browser;
}


I have very little doubt that there is a better way of doing this but this script works for me.

Also please note that because of the way strpos works, the Opera one needs "== false".

If however you are looking for other things such as screen resolution, you are going to need to use Javascript.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1