Alex Poole

Pragmatic PHP, MySQL, Marketing & Technology

Alex Poole header image 2

Link Distribution Script

December 11th, 2008 by alex

I’ve been reading a fair amount about a certain link distribution script that people can use to quickly place links on a load of sites which they control. It would need to be centralised and simple to “drop” into another page. Some people seem to be under the impression it is somehow akin to rocket science. I’d like to dispel that myth in the most convincing way.

If you would like a centralised script that displays a number of random links on any site, here is one I just wrote.

————————————8<————————————

<?php
$links = <<<EOD

http://www.alexpoole.name/|Alex Poole’s Blog
http://www.mattharward.com/|Matt Harward’s Blog
http://www.netfrontiermarketing.com/|Alex Goad’s Blog
http://www.phpguru.org/|Richard Heyes’ Blog
http://10daycashsecret.com/|10 Day Cash Secret
http://www.thelazymarketer.com/blog/|Chris Rempel’s Blog

EOD;

$arrLinks = explode(”\n”, $links);

foreach($arrLinks AS $row){
 if (trim($row)) $cleanArrLinks[]=trim($row);
}

$numlinks = isset($_GET['num']) && (int)$_GET['num'] > 0 ? (int)$_GET['num'] : 1;

$out = Array();

while(count($out) < $numlinks){
 $randlink = explode(”|”, $cleanArrLinks[rand(0, count($cleanArrLinks)-1)]);
 $try = “<a href=\”".$randlink[0].”\”>”.$randlink[1].”</a>”;
 if (!in_array($try, $out)){
  $out[] = $try;
 }
}

die(implode(” | “, $out));

————————————8<———————————— 

Please note the following points:

  • The script is free to use for any purpose (hell, do a box cover and sell it on ClickBank for $49 if you like,) but has no guarantee at all. If it reformats your hard drive, bad luck :) Don’t come moaning to me please.
  • You add links in this format: http://www.url.com|link text (notice the “bar” sign between the URL and the link text. It needs this!)
  • You’d call the script from any site, thus: <?php include(http://mysite.com/script.php?num=3); ?> (that’s for a PHP site. Other scripting languages will include files over HTTP in different ways - talk to your programmer or web designer.)
  • The “num” parameter in the URL is the number of links to show. If this is more than the number of available links in the list, the script will get caught in an infinite loop and end up timing out. It will munch away at your server’s resources until then, and might get you in trouble if you’re on a shared host. You’ve been warned!
  • The same link is not shown more than once.
  • Of course, you could store your list of links in a separate text file or in a database. If you can code a bit you’ll already know how to do this. If not, someone on Rentacoder should be able to set it up for you in 5 mins.
  • If you want to pay me to install or customise this for you, I’d be glad to discuss your requirements - please drop me a line at alexpoole -at- gmail dot com.

Hope you find this useful. Cheers.

Tags:   4 Comments

Leave a Comment

4 responses so far ↓