Checking USER AGENT of Client in Php
In this tutorial for PHP Point - A Tutorial for Beginners we will show you the example of checking user agent in PHP.
The first question will be WHAT IS USER AGENT?
It is a software that is acting on behalf of user. Let’s take browser Example, when you are using your browser for surfing at that time it’s your USER AGENT. If you are working on Google Chrome then your USER AGENT will be “CHROME”, if you are using Mozilla Firefox then your user agent will be “Mozilla”. The USER AGENT values of particular request not only contain browser details but also it include your platform details.
Suppose you are making some project and at particular situation you want some code to be run only on Mozilla Firebox. In that situation you need to add following code in your page.
Example:-
Similarly you can also check the platform of user.
Example:-
Hope this php tutorial is useful for you. Keep following Php Point for more Codes.
The first question will be WHAT IS USER AGENT?
It is a software that is acting on behalf of user. Let’s take browser Example, when you are using your browser for surfing at that time it’s your USER AGENT. If you are working on Google Chrome then your USER AGENT will be “CHROME”, if you are using Mozilla Firefox then your user agent will be “Mozilla”. The USER AGENT values of particular request not only contain browser details but also it include your platform details.
Suppose you are making some project and at particular situation you want some code to be run only on Mozilla Firebox. In that situation you need to add following code in your page.
Example:-
if(strpos($_SERVER['HTTP_USER_AGENT'],’Firefox’)) { //Your Firefox code }
This code will fetch the USER AGENT details of user and our “strpos” function will check whether “Firefox” is present or not in that code. If it return true then your code for Mozilla Firefox browser will be executed.
Similarly you can also check the platform of user.
if(strpos($_SERVER['HTTP_USER_AGENT'],’iPhone’)) { //Your iPhone code }
Hope this php tutorial is useful for you. Keep following Php Point for more Codes.