How to get user device information using php

0
how to get user deivice information using php by jeamshiv

Today I have brought an interesting article for you. How to get user device information using PHP code? You don't need to download any file, nor do you have to include any file. This article is going to helpful for you. I am going to tell you PHP code that can help you to get your client's information. It's mean if someone registered into your website so you can get a person's IP address and the device name of the user with its version.

how to get user deivice information using php

Get device information using $_SERVER['HTTP_USER_AGENT'];

It helps us to get the user's browser information, like the name of the browser and its version, and it also tells us the browser used by the user is the default browser or not. This PHP $_SERVER['HTTP_USER_AGENT'] function help us most.

<?php

echo $_SERVER['HTTP_USER_AGENT'];
$browser = get_browser();
foreach ($browser as $data) {
	echo $data;
}

?>

Get device referal website using $_SERVER['HTTP_REFERER'];

This PHP function helps us to get the user from where the user has redirected to your website.

<?php

	if(isset($_SERVER['HTTP_REFERER'])) {
    echo $_SERVER['HTTP_REFERER'];
}

 ?>

Get user device IP address using getenv("REMOTE_ADDR");

This PHP function helps us to get the user's IP address. This PHP function only works when your PHP code on the server. If you run this function on localhost, it will output one only.

<?php 

  $ipaddress = getenv("REMOTE_ADDR") ; 
  echo "Your IP Address is " . $ipaddress;

  ?>

Get user device IP address using $_SERVER['REMOTE_ADDR'];

This PHP function also helps us to get the user's IP address. It provides us the same output as on the above code.

<?php

 $ipaddress = $_SERVER['REMOTE_ADDR']; 
 echo "Your IP Address is " . $ipaddress;
  
?>

Get computer login user name using php get_current_user();

This PHP function helps us to get the computer's login user name. It means we can get the administrative name from PHP code, but this PHP function works only on localhost.

<?php 
	echo "User name is ". get_current_user();

  ?>

Get server software name using php $_SERVER['SERVER_SOFTWARE']; function

This PHP function helps us to get the name of the server software. It also shows the software version and PHP version.

<?php

    echo "server software ". $_SERVER['SERVER_SOFTWARE'];
  
  ?>

Get server name using php $_SERVER['SERVER_NAME']; function

This PHP function helps us to get the name of the server.

<?php

    echo "Server Name " .$_SERVER['SERVER_NAME'];
  
  ?>

Get server host name using php $_SERVER['HTTP_HOST']; function

This PHP function helps us to get the name of the server host.

<?php

    echo "http host " .$_SERVER['HTTP_HOST'];
  
  ?>

Get server directory and file name using php $_SERVER['PHP_SELF']; function

This PHP function helps us to get the name of the server directory and the file name which is using currently.

<?php

    echo "php self ".  $_SERVER['PHP_SELF'];
  
  ?>

Get server script name using php $_SERVER['SCRIPT_NAME']; function

This PHP function helps us to get same file and it's directory.

<?php

    echo "script name ".$_SERVER['SCRIPT_NAME'];
  
  ?>

Get server request time using php $_SERVER['REQUEST_TIME']; fucntion

This PHP function helps us to get time when the user has a request on a web page. This function does not output in a readable format.

<?php

    echo "Request time ".$_SERVER['REQUEST_TIME'];
  
  ?>

If you want to make readable formate of this function, you need to add some of the code like the below example.

<?php

    $request_time = $_SERVER['REQUEST_TIME'];
    date_default_timezone_set("Asia/Calcutta");
    echo(date("F d, Y h:i:s A", $request_time));
  
  ?>

Get last file modification time getlastmod();

This PHP function helps us to get the last modification time on the PHP file. This function also does not output in a readable format.

<?php

    echo "Get last modify data" .getlastmod();
  
  ?>

If you want to make readable formate of this function, you need to add some of the code like the above code example. On the other hand, you can copy the below codes.

<?php
  date_default_timezone_set("Asia/Calcutta");
  echo" last modify" .(date("F d, Y h:i:s A", getlastmod()));
  
  ?>

What is the use of device information in PHP?

You can use these functions for security reasons. You can also use it for server-side validation. You can also get the users location who are registering on your website. You can also check out the below image to get a new idea in web development. I hope this article was informative.

php user information php mail validation

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !