Detection of Web Browser

6 replies [Last post]
bOtskOOl
Offline
Last seen: 10 years 3 weeks ago
Joined: 2009-02-21
bOt Points: 3500
Re: Detection of Web Browser

You can do it using a simple javascript code -

 

 

<html>

<body>


<script type="text/javascript">

var browser=navigator.appName;

var b_version=navigator.appVersion;

var version=parseFloat(b_version);


document.write("Browser name: "+ browser);

document.write("<br />");

document.write("Browser version: "+ version);

</script>


</body>

</html>

 

 

nitesh
Offline
Last seen: 9 years 36 weeks ago
Joined: 2009-03-26
bOt Points: 370
on the ground level its HTTP

on the ground level its HTTP headers that carry all the info. So if you parse  the headers for the USER AGENT value you have the user's browser

 

 

as far PHP is concerned you can simply use the $_SERVER['HTTP_USER_AGENT'] superglobal. Its exactly what you need

bOtskOOl
Offline
Last seen: 10 years 3 weeks ago
Joined: 2009-02-21
bOt Points: 3500
Re: Detection of Web Browser

You can also use PHP get_browser() function.

Sample code -

 

<?php

echo $_SERVER['HTTP_USER_AGENT'] . "<br /><br />";

$browser = get_browser(null,true);

print_r($browser);

?> 

 

Usage of has $_SERVER['HTTP_USER_AGENT'] also been shown.

programmer
Offline
Last seen: 10 years 40 weeks ago
Joined: 2009-04-14
bOt Points: 86
Thanks a lot....

Thanks a lot....

 

will it be better to use Javascript or php??

 

which one is more effective n why?

nitesh
Offline
Last seen: 9 years 36 weeks ago
Joined: 2009-03-26
bOt Points: 370
PHP or javascript

It depends for what you want the information

 

If you want to process this information and perform some operations on the server side PHP would be a better option.  Firstly since javascript works on the client  side , the user may easily modify this information before it reaches you.  This will also be more secure than relying on javascript.

 

 

programmer
Offline
Last seen: 10 years 40 weeks ago
Joined: 2009-04-14
bOt Points: 86
Thanks!!

Thanks a lot!!

 

It actually helped  in solving a lot many problems...:)