Forgot Password / Register
Site Statistics
Total Members: 510
Total Tutorials: 242
Newsest User: Hp
Todays Unique Hits: 120
0 Users 3 Guests Online

Random Link or Image

Use this code below to display a random link or image.

Well this code is explained in the comments:
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?
//your links file should be in the following format:
//http://domain.com|text to display
//http://domain2.com|more text to display
define("linkfile""links.txt"); //points linkfile to links.txt
$links file(linkfile);//points $links to the linkfile
srand((double)microtime()*1000000);//generates a radom number
$randline rand(0,count($links)-1);//picks a random line on the linkfile
$link explode("|",$links[$randline]);//seperates the link from the text to display

echo "<a href="$link[0]">$link[1]</a>";//echos the link and the description
//you could also use this to link random images:
//echo "<a href="$link[0]"><img src="$link[1]" /></a>";
//just format your links.txt file in the following format:
//http://domain.com|url the image
?>


Works pretty good. Just remember in the links.txt file or whatever you decide to name it, you use the right format that it explains in the comments.
3xS
Author:
Views:
1309
Rating:
There are currently no comments for this tutorial.