PHP Link Rotator, PHP Link Rotator Script
Posted on: April 14, 2006 at 12:00 AM
This script is useful for those who have no database access. Use just a few lines of this PHP code to output a random banner or random link into your HTML page.

PHP Link Rotator

In this tutorial I'm going to learn you own to create a simple rotation script. It can be used for rotating banners or for your links page. You don't need to have database access, it is just one php file.

Ok let's start with some info.

How would I do rotating ?


I need an array containing something to output and I need to get elements in a random order form that array to show them on the page. Here we create an array:

$codes = array(
    "<a href=roseindia.net><img src=banner1.gif></a>",
    "<a href=newstrackindia.com><img src=banner2.gif></a>",
    "<a href=javajazzup.com><img src=banner3.gif></a>"
); br>
It should contain the set of all possible codes to show on the page.

Next we should randomly get one element and show it on the page. This part can be done in numerous ways:
1. First way is to fetch an element with a random index from array. But in this case when we get a random index we need to check if we already outputted that element or not.
2. Second way is to fetch an element with a random index and then delete it from an array so we don't have to check everytime when getting new random value.
3. Third way is to sort array in a random order and just output its contents.
II think the most easy way is third, so let's build the script !

To sort array in a random order I use these two lines: code>

srand ((float) microtime()*1000000);
shuffle($codes);

First line written above will seed random values generator and the second will sort an array randomly. To get better results it is recommended to place srand function as far as it is possible from the line that gets a random value. We will do it in the final script further. And the last part of the script will output records on the page:

while(list(, $code) = each($codes)) {
      echo "$code";
}

You can use this simple rotating mechanism for placing links, banners, or just any text. I used the code shown below to output two of three possible links on the page:


<html>
<body>
Check out these links:<br>
<?
$codes = array(
&    "<a href=roseindia.net><img src=banner1.gif></a>",
    "<a href=newstrackindia.com><img src=banner2.gif></a>",
    "<a href=javajazzup.com><img src=banner3.gif></a>"
);br>
shuffle($codes);
$i=0;
$number=2; while(list(, $code) = each($codes)) {
       if ($i>=$number) { break; }
       echo "$code";
       echo '<br>';
       $i++;
}
?>
</body></html>

OOf course this script can't show you the number of views for each link. But with some cool modifications (writing the number of views into a file) you can create your own advanced banner rotation software and sell it to someone.
More Tutorials on roseindia.net for the topic PHP Link Rotator, PHP Link Rotator Script.
PHP Link Rotator, PHP Link Rotator Script
PHP Link Rotator In this tutorial I'm going to learn you own to create a simple rotation script. It can be used for rotating banners or for your links page. You don't need to have database access, it is just one php file
 
php generate link - PHP
php generate link  How can i generate links in PHP for my photo gallery app
 
php a href link
php a href link  i guess... we can write the href in a similar way as in html to create a link
 
php
php  i want to know about php and php plateform required software to make php program and database that used in php program?   Please visit the following link: PHP database
 
php
php  i want to know about php and php plateform required software to make php program and database that used in php program?   Please visit the following link: PHP database
 
php
php  How to catch a image and link click counters using Ajax php can any one help me
 
php
can learn php mysql connectivity examples from the given link: PHP Mysql Connectivity
 
PHP function is_link and example
Syntax for PHP is_link() Function bool is_link(file_name) is_link() function checks whether the given file is the link file or not Example of PHP is_link() Function Code <?php     $f="
 
PHP
for the database that you will link to this Main Menu. Display appropriate
 
ModuleNotFoundError: No module named 'rotator'
ModuleNotFoundError: No module named 'rotator'  Hi, My Python... 'rotator' How to remove the ModuleNotFoundError: No module named 'rotator... to install padas library. You can install rotator python with following command
 
Array length in PHP - PHP
Array length in PHP  a function to get the array length in PHP.  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/php/phparray/php-array-length-for.html Thanks
 
Replace String in PHP - PHP
Replace String in PHP  What is the fastest way of replacing string in PHP Code?  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/php/phpbasics/PHP-Array-Replace.html Thanks
 
Static Method in PHP - PHP
Static Method in PHP  So far I can easily use the normal functions as variable in PHP? but how can use static method?  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/php/phpoop/php
 
Multidimensional Array in PHP - PHP
in PHP completely goes over my head. Can any one present a better explanation on it with an example? Also the structure of Multidimensional Array in PHP.  Hi Friend, Please visit the following link: http://www.roseindia.net
 
Mysql-Php code
Mysql-Php code  I want to mysql script for query data from two tables..., Please visit the following link:ADS_TO_REPLACE_1 Php Mysql Thanks   Hi Friend,ADS_TO_REPLACE_2 Please visit the following link: Php Mysql
 
php backup database script - PHP
php backup database script  please post the backup database script in PHP. Thank u very much
 
ModuleNotFoundError: No module named 'archive-rotator'
ModuleNotFoundError: No module named 'archive-rotator'  Hi, My... named 'archive-rotator' How to remove the ModuleNotFoundError: No module named 'archive-rotator' error? Thanks   Hi, In your python
 
ModuleNotFoundError: No module named 'archive-rotator'
ModuleNotFoundError: No module named 'archive-rotator'  Hi, My... named 'archive-rotator' How to remove the ModuleNotFoundError: No module named 'archive-rotator' error? Thanks   Hi, In your python
 
ModuleNotFoundError: No module named 'archive-rotator'
ModuleNotFoundError: No module named 'archive-rotator'  Hi, My... named 'archive-rotator' How to remove the ModuleNotFoundError: No module named 'archive-rotator' error? Thanks   Hi, In your python
 
ModuleNotFoundError: No module named 'folder-rotator'
ModuleNotFoundError: No module named 'folder-rotator'  Hi, My... named 'folder-rotator' How to remove the ModuleNotFoundError: No module named 'folder-rotator' error? Thanks   Hi, In your python
 
ModuleNotFoundError: No module named 'archive-rotator'
ModuleNotFoundError: No module named 'archive-rotator'  Hi, My... named 'archive-rotator' How to remove the ModuleNotFoundError: No module named 'archive-rotator' error? Thanks   Hi, In your python
 
ModuleNotFoundError: No module named 'folder-rotator'
ModuleNotFoundError: No module named 'folder-rotator'  Hi, My... named 'folder-rotator' How to remove the ModuleNotFoundError: No module named 'folder-rotator' error? Thanks   Hi, In your python
 
linking php page to other php pages
linking php page to other php pages  How to link the PHP Page to other PHP page
 
php
php  what is the script
 
php download file script
php download file script  PHP script to download file in IE
 
to display like and dislike votes for a link
to display like and dislike votes for a link   Am new to php i wrote a code for posting the links but now i want to add like and dislike for that each link which is visible on retrieve page i think it can be done by using Ajax
 
php browser detection script - PHP
php browser detection script   I need a browser detection script in PHP. I am creating my application compatible to firefor, mozila and IE too
 
link
the link the table is displayed and other links were hidden if i want to click the next link i have to refresh the page instead i want to do is when i click the link the table should display and again when i click the link the table should
 
Php frameworks
Php frameworks  What are the best framework in php to learn and work on? I know Smarty only.   Please visit the following link: PHP Tutorials Here you will find several php tutorials with good illustration
 
php question
, CMS, Shopping cart etc. Link: PHP Basic Tutorials ThanksADS_TO_REPLACE_3...php question  hi i am ramesh, i want to learn php. with wamp server is it good to learn the php.   Hi, Please read at PHP and WAMP
 
link
link  hey frnds can anyone plz tell me how can i store my videos as link in my database and can retrive the video using servlet by clicking on to that link .it may be confusing sorry about that and if someone can than plz help me
 
PHP Comma vs Period - PHP
PHP Comma vs Period  Explain PHP Comma vs Period. And also how can one show a comma within a comma separated file.   Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/php/phpbasics/PHP
 
LINK
LINK  Thank you friend.cant we use single click instead of double click and also for four link u has given the example but i have 14 links in that case wat i should do
 
problem on php
problem on php   l have five tables and build them as forms and link between them php and database and i want to build query between them plz help me soon   PHP MySQL Tutorials
 
link
link  how can we give hyperlinks on data retrieved from the database and when a particular option is clicked it should be saved in another database and details related to that link should be diaplay and stored in the database
 
LINK
LINK  I have four links which link to a table,if i click one link... i want to ask is when i click the link the table is displayed and other links were hidden if i want to click the next link i have to refresh the page instead i
 
php - Ajax
php  ajax wiht php registration coding with validation coding also  Hi mohamed Please follow this link to find your problem http://www.roseindia.net/ajax/ajaxlogin/ajax-registration-program.shtml Thanks
 
link

 
ModuleNotFoundError: No module named 'rentier-scrapy-proxy-rotator'
ModuleNotFoundError: No module named 'rentier-scrapy-proxy-rotator'  ...: No module named 'rentier-scrapy-proxy-rotator' How to remove the ModuleNotFoundError: No module named 'rentier-scrapy-proxy-rotator' error
 
ModuleNotFoundError: No module named 'scrapy-proxy-rotator'
ModuleNotFoundError: No module named 'scrapy-proxy-rotator'  Hi...: No module named 'scrapy-proxy-rotator' How to remove the ModuleNotFoundError: No module named 'scrapy-proxy-rotator' error? Thanks   Hi
 
ModuleNotFoundError: No module named 'django-ad-rotator'
ModuleNotFoundError: No module named 'django-ad-rotator'  Hi, My... named 'django-ad-rotator' How to remove the ModuleNotFoundError: No module named 'django-ad-rotator' error? Thanks   Hi, In your
 
Comment PHP Script - MobileApplications
Comment PHP Script  I wanted to write a PHP Script that makes it possible to post the comment on reply. A user can add his comment to any of the reply in the forum. How can I do
 
MySQL PHP Insert
MySQL PHP Insert       Mysql PHP Insert is used to execute the Mysql function ( ) insert queries in the PHP server side script and print the records on the browser
 
PHP DATABASE
coding in php.its very urgent sir   Please visit the following link: PHP...PHP DATABASE  Hi sir Good Morning.i want the coding for following description 1)create the html page with first,lastname,mail id,mobile no,address
 
PHP hide file path
PHP hide file path  PHP to read a path and convert that to the virtual link
 
JavaScript link
of the Link object</h2> <script language="JavaScript"> function... JavaScript link...; In this section, you will learn about the text property of Link object in JavaScript
 
PHP Chat Systems A MySQL Driven Chat Script Tutorial
PHP Chat Systems A MySQL Driven Chat Script Tutorial   ... script using PHP and MySQL database. The application will allow visitors...; log me in</a> <?php $link=mysql_connect("localhost"
 
project on php
project on php   suppose i have five tabels and i must form them html then link them database and php then i want to make query between them these five tabels and data in each one pleaze help me Table of suppliers Source
 
PHP mysql database backup script - PHP
PHP mysql database backup script  How can i get the database backup using PHP mysql database
 
php - Ajax
php  hi i need ajax registration form validation coding   Hi friend, I am sending you a link. This link will help you. Visit for more information: http://www.roseindia.net/ajax/ajaxlogin/ajax-registration
 
Ads

Related Tags for PHP Link Rotator, PHP Link Rotator Script:


Ads

 
Advertisement null

Ads