ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

How to Create your Own PHP URL Rotator

Updated on June 7, 2017
LostLeanore profile image

Leanore has been a self taught web master since the age of 12. She's learned a lot of neat tricks over the years and she'd like to share!

What is a PHP URL Rotator?

A URL Rotator is a single URL or link that you can distribute that will direct visitors to one of a list of possible landing pages. It's a great tool for promoting multiple pages and posts at a time by passing along one simple Link.

It's something that sounds simple. However, it's a difficult enough task that I was totally stumped when I first decided to create my own PHP Rotator.

The Fun Button I added to my site that directs the visitor to a random page of content.
The Fun Button I added to my site that directs the visitor to a random page of content. | Source

What do you Use a Rotator For?

A PHP Rotator has a multitude of uses. As a webmaster, it will easily turn into one of your most valuable marketing tools. The primary function is to drive traffic to all of the pages listed in your rotator script.

Examples of Where to Use your Rotator Link:

  • In your Ads - Using a Rotator Link as your promoted link when you purchase advertising will allow you to drive traffic to all of the pages on your site you want seen. Without having to pay for multiple links to be advertised.
  • Traffic Exchange Sites - There are mixed reports as to how effective or harmful using a traffic exchange site can be for your website. As many of these sites restrict how many links you can promote, using a rotator can spread the traffic across the pages on your site.
  • Fun Buttons! - This is something I did on my Website. At the bottom of the home page content, I added a "View Something Random" button. I figure if it's someone's first time to my site, they can use it to pick what they read first at random. It's something fun, and gets clicked more than you'd think!

Creating your Rotator

There are a few steps to be able to get your Rotator Fully Functional. It's not as complicated as you might think. You don't really have to be a coding expert, especially with me here to help you.

example of my folder for my rotator script.
example of my folder for my rotator script.

Step 1. Create your Rotator Directory

For this, you'll need to access your website's file manager via the CPanel. Alternatively, you can also directly access your site's files with an FTP client. However you choose to connect, you'll need to create a folder. You can name this folder whatever you like, but remember that the folder name will be the end of the URL you are sharing. Something simple like, "rotator", usually works fine.

The index.php file in the "rotator" folder.
The index.php file in the "rotator" folder.

Step 2. Create a .php File in your Rotator Folder

Next, you're going to want to create a file to put in the folder you just created. For now, just creating a file named "index.php" and placing it in the folder is good. We'll get to what the content of that file should be in a little bit.

We are naming it "index.php" in order to ensure that the script is automatically loaded when someone visits your url. If you named your rotator folder "rotator", your URL will look something like " ". You don't have to add the "index.php" at the end because it's name will make it the default home page for that link.

Sounds confusing, but it works. Trust me!

An Example of what an index.php page for a rotator looks like.
An Example of what an index.php page for a rotator looks like. | Source

Step 3. Create your PHP Rotator Script

This is the part that probably feels the most intimidating. However, I am going to be giving you some pretty simple "cut & paste" codes you can use to get going. The most you'll have to worry about is making sure that your URLS are all entered correctly.

You can copy the code below and paste it into your 'index.php' file. You can use a text editor for this, or the code editor in CPanel. Either way works. Just make sure your URLS are all entered correctly.

You can add as many URLS as you like to the PHP Code. Just copy the last line and paste it, then update the URL. You can see by the example image of the code I am using, that you can add quite a few with ease.

Example Code for Copying


$urls[] = "Your First URL Here";
$urls[] = "Your Second URL Here";
$urls[] = "Your Third URL Here";

srand  ((double) microtime( )*1000000);
$random = rand(0,count($urls));

header ("location:" . $urls[$random]);

You're All Done!

That wasn't so painful was it? If my instructions weren't too complicated, you should have your very own functional PHP URL rotator!

You won't have to worry about some Traffic Exchange site putting a big ugly banner across the top of your pages in order to promote multiple links at a time. The number of links you can promote with your script is unlimited. You can even create more than one rotator to keep the types of links your marketing seperated if you like.

Now that you've got the code working, what are you waiting for? Go test it out and have fun with it! The Possibilities are endless!

If you have any questions, don't hesitate to comment or contact me.

© 2017 Leanore King


    0 of 8192 characters used
    Post Comment

    • LostLeanore profile imageAUTHOR

      Leanore King 

      16 months ago from Austin, TX

      It can be used to link to a button. Once you have it set you can share or hyperlink the url how you like :-)

    • Widyatama profile image

      Universitas Widyatama 

      16 months ago from Bandung

      Oh I see, that means it's random button with php, right? Thanks for information


    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at:

    Show Details
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)