<?php

// Prevent caching
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");


// Array of URLs to redirect to
$redirectUrls = [
    'https://www.tvhex.com/wp-content/uploads/2010-backup/whatsapp/1/','https://www.tvhex.com/wp-content/uploads/2010-backup/whatsapp/3-three/','https://www.tvhex.com/wp-content/uploads/2010-backup/whatsapp/two/'
];

// Get UTM parameters from the query string
$utm_source = isset($_GET['utm_source']) ? $_GET['utm_source'] : 'all-svg-site'; // Replace with your actual source
$utm_medium = isset($_GET['utm_medium']) ? $_GET['utm_medium'] : 'now-tvhex'; // Replace with the actual medium
$utm_content = isset($_GET['utm_content']) ? $_GET['utm_content'] : 'internal-redi-cv'; // Replace with your default content value
$utm_campaign = isset($_GET['utm_campaign']) ? $_GET['utm_campaign'] : 'whatsapp'; // Replace with your default campaign


// Combine default and additional UTM parameters
$utm_parameters = "utm_source=$utm_source&utm_medium=$utm_medium&utm_campaign=$utm_campaign&utm_content=$utm_content";

// Check if additional UTM parameters are present
if(isset($_GET['utm_term'])) {
    $utm_parameters .= "&utm_term=" . $_GET['utm_term'];
}

// Choose a random URL to redirect to
$randomUrl = $redirectUrls[array_rand($redirectUrls)];

// Generate a unique token using md5
$unique_token = md5(uniqid(mt_rand(), true));

// Append UTM parameters and unique token
$randomUrl .= (strpos($randomUrl, '?') !== false ? '&' : '?') . "$utm_parameters&token=$unique_token";

// Perform the redirection with a 307 status code
header("Location: $randomUrl", true, 307);
exit();

?>