<?php

$links = [
    'https://masuk.situskeren777.website/',
    'https://masuk.situskeren777.monster/',
    'https://situskeren777.monster/',
];

$total = count($links);

// Ambil posisi terakhir dari cookie
$index = isset($_COOKIE['rotator'])
    ? (int) $_COOKIE['rotator']
    : 0;

// Amankan index
$index = $index % $total;

$target = $links[$index];

// Tentukan urutan berikutnya
$next = ($index + 1) % $total;

// Simpan posisi di browser visitor
setcookie('rotator', (string) $next, [
    'expires'  => time() + 86400,
    'path'     => '/',
    'httponly' => true,
    'samesite' => 'Lax'
]);

// 302 Redirect
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Location: ' . $target, true, 302);
exit;