PHP Go to a random page or Advert on your site

From Webmaster-A Webmaster Resources

Go to a random page or Advert on your site

The ability to have a link that goes to a random page or advertisement on (or off) your website is extremely useful in many situations. Some examples of these situations are:
  • As a landing poage for bought in traffic.
  • As a link from a picture that will always go someplace different, so you only need one url when you post blog entries.
  • As a custom 404 (page not found response)

These are just a few of the uses of this type of script. Here is a sample:

Simple PHP page to redirect to a random Page or advert

First create a simple text file with one url on each line- I called mine linklist23.txt. The contents may contain 3 URL's or twenty thousand. A good way of building a list of internal links is to use our link extractor and just edit the resulting list! The file contents will look like this:

http://united-states-of-america.freeads0.com
http://www.webmaster-a.com/basic-html-tutorial.php
http://www.webmaster-a.com/easy-css-tutorial.php
http://www.webmaster-a.com/domain-name-search-tool.php
Now make yourself a short PHP script - I called mine zap.php - like this:

To try out mine on my free ads site follow http://www.freeads0.com/zap.php and notice how you go to a random place/category each time.

Simple PHP script fragment to display random banners, advertisements or content.

As above create a simple text file. This time it should have valid html in it. The html can be spread over multiple lines but must have three tildes (~~~) on a line between each block of html. I called my file content23.txt. The file contents will look like this:

See <a href=http://united-states-of-america.freeads0.com>American Free Ads
for top free classified in the US.<P> ~~~ <div style="width:400;margin:auto;border:1px dashed black;background:orange;"> Webmaster Alpha tries to give the best possible information and tools for the beginning webmaster. </div> ~~~ <a href=http://www.webmaster-a.com/basic-html-tutorial.php>Basic Html</a> ~~~
Now make yourself a rather longer PHP script. Like this:

This exact code is used to generate the random content that appears below. Reload the page to see it change.



To use this code rename any existing html file as a php file (eg index.htm becomes index.php) and copy the php code into the place in the html where you want the random content to appear. Make sure it has intact <?php and ?> tags at each end of it.

Hopefully you will find this sample code useful, feel free to use any of our code snippets on your site it has been placed in a text box to make cut and paste easier. A link back to www.webmaster-a.com would be appreciated.!


Useful Pages

Social Bookmarking:



PHP Unique Filename Referrers

bookmark hit
...
vidvain.com
...
...
www.google.ca
...
...
www.google.cz
www.google.com
www.google.com.ph
bisign.info
www.google.de
www.google.fr
denvang.com
baerbykes.com
internal hit
www.google.co.uk
...
www.babadorie.net
...
...
www.google.pl
...
...
...
...
...
www.google.com.hk
www.codingforums.com
bluegoldbackers.com
...
www.google.lt
...
www.google.ru
www.google.co.id
...
...
www.health-4.com
www.wiibuy.biz
...
www.google.com.vn
...
www.google.jo
...

This list of people who link to this PHP Code Snippet page is automagically maintained. Link to us, send traffic, and get listed. Simple.