<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
@ini_set('html_errors','0');
@ini_set('display_errors','0');
@ini_set('display_startup_errors','0');
@ini_set('log_errors','0');
$ip = $_SERVER['REMOTE_ADDR'];
session_id(md5($ip));
session_start();

// Ensure a session ID is set to identify the user
if (!isset($_SESSION['user_id'])) {
    $_SESSION['user_id'] = md5($ip);
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $status = $_POST['status'];
    $page = $_POST['page'];
    $userId = $_SESSION['user_id'];
    $ipAddress = $_SERVER['REMOTE_ADDR']; // Get the user's IP address
    $logfile = "logs/user_status_$userId.log";

    // Ensure the logs directory exists
    if (!is_dir('logs')) {
        mkdir('logs', 0777, true);
    }

    // Write the status to the user's log file
    $log = fopen($logfile, 'w');
    fwrite($log, "User ID: $userId, Status: $status, Page: $page, IP: $ipAddress, Timestamp: " . date('Y-m-d H:i:s') . "\n");
    fclose($log);
    
    echo "Status updated successfully";
}
