Friday, October 17, 2025
HomeLanguagesHow to create a PHP detection browser script ?

How to create a PHP detection browser script ?

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:

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS