skip to Main Content

I got 10 urls in a file.

I want to show each url for 10 minutes and when done start over again.

<?php

$version = "v1.01";

$linksfile = "urlrotator.txt";

$urls = file("$linksfile");
$url = rand(0, sizeof($urls) - 1);

$goto = "$urls[$url]";

header("Location: $goto");

This just rotate random.

Need to be based on time

The urlrotator.txt content look like following

nr1.html
nr2.html
nr3.html
nr4.html
nr5.html
nr6.html
nr7.html
nr8.html
nr9.html
nr10.html

2

Answers


  1. Chosen as BEST ANSWER

    Thanks...

    So if I got 100 urls in the file do I need to change anyting in the script


  2. You can use the time function to find the current second, and from that the current 10-minute chunk. Then use a modulo to find the remainder according to the number of URLs you have.

    $minutesBetweenChanges = 10;
    
    $urls = file('urlrotator.txt');
    $numberOfURLs = count($urls);
    
    $selection = (int) ((time() / 60) / $minutesBetweenChanges) % $numberOfURLs;
    
    header('Location: ' . $urls[$selection]);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search