How can we get the browser properties using php?
How can we get the browser properties using php?
Page 1 of 12 Replies - 3000 Views - Last Post: 21 August 2010 - 09:46 AM
Replies To: How can we get the browser properties using php?
#2
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
#3
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.
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.
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.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|