• home
  • Email: trainings@synapseindia.careers

Blogs

back

HOW TO FIND TOTAL NO. OF VISITORS

Sep 22, 2015

By using the concept of session variable one can count or store the total number of visitors.   // Start session session_start(); // Connect SQL include("myDb.php"); myDb->connect(); // Get the ammount of visits $res = myDb->fetch("SELECT COUNT(logID) AS 'count' FROM tablename"); echo "Total visitors: ". $res[0]['count']; // Check if you have been counted this session if(!isset($_SESSION['HasBeenCounted'])) { // Fetch the ammount of times // this IP has been counted today $IP = $_SERVER['REMOTE_ADDRESS']; $res = myDb->fetch("SELECT logID FROM tablename WHERE IP = '$IP' AND logDate = NOW()"); // If it has not been counted; add it if(count($res) == 0) { myDb->query("INSERT INTO tablename(IP, logDate) VALUES('$IP', NOW())"); } // Set the $_SESSION var $_SESSION['HasBeenCounted'] = true; }  

SynapseIndia (CEO: Shamit Khemka)