Skip to content
Related Articles

Related Articles

How to create a PHP detection browser script ?

Improve Article
Save Article
  • Last Updated : 10 Mar, 2022
Improve Article
Save Article

A browser script is used to find the complete information of the web browser. A web browser is working on the hypertext transfer protocol and retrieves all the information on the internet and displays it on your desktop so that you can access all the things from anywhere. 

In this article, we will show how to retrieve the browser information in the below examples.

Example: $_SERVER is the inbuilt function in the PHP used to display the information of various things. HTTP_USER_AGENT gives the browser details. The output is shown as the result you can get from the function when you run the script.

PHP




<?php
    echo "Your User Agent is :" . $_SERVER ['HTTP_USER_AGENT']."<br>";
?>


Output:

Your User Agent is:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) 
Chrome/98.0.4758.102 Safari/537.36

get_browser(): The get_browser() function in PHP is an inbuilt function that is used to tell the user about the browser’s capabilities. This function looks up the user’s browscap.ini file and returns the capabilities of the user’s browser.

Syntax:

get_browser($user_agent, $return_array)
  • $user_agent: You can put a value equal to null because it takes the HTTP user_agent value but if you want to find the details of another browser then you can pass the user_agent of that browser.
  • $return_array: It is boolean variable. If it is true, then it gives the result in an array otherwise returns an object.
  • <pre> is used to display the array in human-readable form.

Example: If you want more details of the browser then you can use the following function.

PHP




<?php
  
    $browser = get_browser(null, true);
    print "<pre>";
    print_r($browser);
    print "</pre>";
?>


 

Output:

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!