How to Get Visitor Details Using PHP and MySQL

In this tutorial we will show you how to get and display visitor details using PHP and MYSQL. We get details like visitor ip address, current visiting page, webpage visitor come from, time and date and what platform and browser. You may also like How to Block User From Visiting Website Using PHP and Multiple Image Upload in PHP.

PHP Code

<?php
    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $page = "http://".$_SERVER['HTTP_HOST']."".$_SERVER['PHP_SELF'];

    $datetime = date("F j, Y, g:i a");
    $useragent = $_SERVER['HTTP_USER_AGENT'];

    echo "<p>IP Address : ".$ipaddress."</p>";
    echo "<p>Current Page : ".$page."</p>";
    echo "<p>Current Time : ".$datetime."</p>";
    echo "<p>Browser : ".$useragent."</p>";

    mysqli_query($con,"insert into slug (ip,page,Currenttime,Browser) values('$ipaddress','$page','$datetime','$useragent')");
 
?>

Leave a Reply

Your email address will not be published. Required fields are marked *