Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7913857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:56:27+00:00 2026-06-03T13:56:27+00:00

I want to create an URL rotator script that will rotate my URLs in

  • 0

I want to create an URL rotator script that will rotate my URLs in a specific order,not randomly.

let say I have 100 URLS to rotate, I have them ordered and the rotator will show them from the first one until the last one, then return to the first URL and so on.

if possible can it be a simple php script with no database?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:56:28+00:00Added an answer on June 3, 2026 at 1:56 pm
    <?php
    define('FILEDB', 'count.db');
    define('URLDB', 'url.db');
    
    function readURLS()
    {
      $fp = fopen(URLDB, 'r');
    
      if( null == $fp )
        return false;
    
      $retval = array();
      while (($line = fgets($fp)) !== false)
      {
        $retval[] = $line;
      }
    
      return $retval;
    }
    
    $list = readURLS();
    
    if( false === $list )
    {
      echo "No URLs available";
    }
    else
    {
      $fp = fopen(FILEDB, 'a+');
    
      $count = (fread($fp, filesize(FILEDB)) + 1) % count($list);
    
      ftruncate($fp, 0);
      fwrite($fp, "{$count}");
      fclose($fp);
    
      echo $list[$count];
    }
    

    this works.


    updated with new requirements.
    You’ll need a file named url.db (or whatever you fill in after the define('URLDB', 'xxx')
    Each line is an URL entry.

    count.db can exist, but doesn’t need to. It is better to create one with a simple 0 in it.

    It will rotate through all URL entries in the url.db file on each ‘request’.

    However this is not concurrent safe. If person A requests the page and person B does as well there might be a chance that A and B see the same URL if B reads count.db before A has written the new contents to count.db

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to create url pattern that lead to filter in jsf2. I tried
Let's say I have a web request: WebRequest webRequest = WebRequest.Create(Url); webRequest.BeginGetResponse(this.RespCallback, webRequest); Now
I want to create a simple URL shortner that would do the following: http://example.com/code
I want to create URL re-write rules for following URL in htaccess. http://example.com/vedios/category/fun/ ->
In my JSF web-app, I want to create a URL for the user to
I want to use URL such as /Image/sample.png I create route, but it does
I want create module which update list of usb devices automatically (not only mass
I want to create a stored procedure (on SQL Server 2005) that fetches a
I want to create a url like www.facebook.com/username just like Facebook does it. Can
I want to create a flickr photo url by calling variables from my json_decoded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.