A little php help please!

nutsforsports

Junior Member
Joined
Aug 18, 2008
Messages
183
Reaction score
49
What I need is a quick script (code) for php that will take random urls from a text file and go to it.

So...

User clicks link and the code grabs a random url from a text file and goes to it.


I don't think it is hard to do, just not a programmer so I have no idea on how to do this.

Thanks!
 
how many urls are you talking about? 1000's or like 5?
 
If you don't get any takers you can do it yourself. Grab AUTOMATE, it should be in the downloads here somewhere. It's not hard to figure out.
 
quick and dirty way of doing it probably easier ways but for now...

create a file called urllist.php with the following code:

<?php
$url1="http://www.yourdomain1.com";
$url2="http://www.yourdomain2.com";
$url3="http://www.yourdomain3.com";
?>

ie add all your 20 links...

on your actual page where you want to show your random url do this:

<?php
//pull all your url values from urllist.php
include 'urllist.php';
// create a random number between 1 and the total number of urls in your urllist.php file in this example we use 20
$x=(rand(1,20));
//create prefix for random url
$randomurl="$url";
// echo out the random url in a href - you can format this anyway you want ie add a class, title, img src, target, etc
echo "<a href=\"$randomurl$x\">your anchor text here</a>";
?>

not tested this but it should work...

hth
 
Last edited:
PHP:
[PHP]<?
if(!empty($_GET['r']) && $_GET['r'] = 'true') { 
$site = fopen("websites.txt","r"); $s = filesize('websites.txt');
$site = fread($site, $s);
$site = explode("\n",$site);
$x = array_rand($site);
header('Location: '.$site[$x]);
}


?>

HTML code:
Code:
<a href="<?php echo $_SERVER['PHP_SELF'].'?r=true'; ?>">Anchor text</a>

Make sure the websites in 'websites.txt' start with the http:// protocol.
 
Back
Top