Get client system information in php

In PHP, you can retrieve certain system information from the client's machine using the $_SERVER superglobal variable and other PHP functions.

Here are some examples:

  1. User Agent
  2. IP Address
  3. Screen Resolution
  4. Timezone

User Agent

The user agent string contains information about the client's browser and operating system. You can retrieve it using the $_SERVER['HTTP_USER_AGENT'] variable.

<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];
echo "User Agent: $user_agent";
?>


IP Address

You can retrieve the client's IP address using the $_SERVER['REMOTE_ADDR'] variable.

<?php
$ip_address = $_SERVER['REMOTE_ADDR'];
echo "IP Address: $ip_address";
?>


Screen Resolution

You can retrieve the client's screen resolution using JavaScript and pass it to PHP using AJAX.

<script>
var width = screen.width;
var height = screen.height;

$.ajax({
    type: "POST",
    url: "get_resolution.php",
    data: { width: width, height: height }
});
</script>

In the get_resolution.php file, you can retrieve the values using the $_POST variable. For example:

<?php
$width = $_POST['width'];
$height = $_POST['height'];
echo "Screen Resolution: $width x $height";
?>


Timezone

You can retrieve the client's timezone using the date_default_timezone_get() function.

<?php
$timezone = date_default_timezone_get();
echo "Timezone: $timezone";
?>

kabeer

Added  Mar 04, 01:17 pm

Article tags

Php
×
SignUp with Email
X