URL rotator

A URL rotator is a tool that allows you to rotate a group of URLs in a specified order or randomly. It can be useful for a variety of purposes, such as splitting traffic between multiple websites, sharing links to multiple products, or testing the effectiveness of different landing pages.

URL rotators work by redirecting visitors to one of the URLs in the rotation based on the rules that you set. For example, you might specify that the rotation should start with URL A, then rotate to URL B after five visits, and then rotate to URL C after ten visits. Or, you might specify that the URLs should be rotated randomly with equal weighting.

There are a number of different tools and services that offer URL rotation functionality, including some website builders, WordPress plugins, and standalone services. Some popular options include AdRotate, RotatorGenie, and LinkTrackr.

To create a URL rotator in PHP, you can use an array to store the URLs and a random number generator to select a URL to display. Here is an example:

$page[1] = "url1";
$page[2] = "url2";
$page[3] = "url3";
$page[4] = "etc..";

if(!isset($HTTP_cookie_VARS['page'])){ $n=is_countable($page) ? count($page) : 0;
$rand=random_int(1,$n); setcookie("page",$rand,['expires' => time()+1000]);
header('location:'.$page[$rand]); }else{ $go=$page[$_COOKIE['page']]; header('location:'.$go); }



// List of URLs with their priorities
$urlList = array(
        array('url' => ‘url-1', 'priority' => 2),
	array('url' => ‘url-2', 'priority' => 7),
	array('url' => ‘url-3’, 'priority' => 5),
	array('url' => ‘url-4', 'priority' => 3),
	array('url' => ‘url-5', 'priority' => 8),

// Check if a cookie is set
if (isset($_COOKIE['visited'])) {
    $visited = json_decode($_COOKIE['visited'], true);
} else {
    $visited = array();

// Sort the URL list by priority
usort($urlList, function ($a, $b) {
    return $b['priority'] - $a['priority'];

// Loop through the URL list and find the first unvisited URL
foreach ($urlList as $urlItem) {
    if (!in_array($urlItem['url'], $visited)) {
        $url = $urlItem['url'];

// If all URLs have been visited, start over
if (!isset($url)) {
    $url = $urlList[0]['url'];
    $visited = array();

// Add the current URL to the visited list and set a cookie
array_push($visited, $url);
setcookie('visited', json_encode($visited), time() + (1000 * 1), "/"); // cookie lasts for 30 days

// Redirect to the selected URL
header('Location: ' . $url);


*replace url1, url2, with the url you want… and this code can use your own domain, I have tried the script above myself.