laze.net

twist of fait accomplis

June 26, 2002
Simple Backlinking with PHP

Hey, pals, backlinking is all the rage! Not only are the cool kids doing it, even the dorky kids have caught on!

If you'd like some fancy little backlinks to appear on your site, here's some homegrown PHP code you're welcome to...

Version 1.11 (July 16, 2002)
<?
   $recentfile = "/full/path/to/backlink.txt";
   $mydomain = "laze.net"; // REPLACE WITH YOURS
   $displaynum = 20;
   $displaychar = 24;

   $recent = file($recentfile);
   $start = 0;
   $amount = count($recent);
   if ($amount >= $displaynum) { $start = 1; $amount = $displaynum; }
   for ($x = ($amount-1); $x >= 0; $x--) {
      if (eregi("google\.",$recent[$x]) || eregi("search\.msn\.",$recent[$x]) || 
          eregi("atomz\.com",$recent[$x]) || eregi("lycos\.",$recent[$x]) || 
          eregi("altavista\.",$recent[$x])) {
         if (eregi("google\.yahoo",$recent[$x])) {
            list($first,$rest) = split("p=", $recent[$x]);
         }
         elseif (eregi("lycos\.",$recent[$x])) {
            list($first,$rest) = split("query=", $recent[$x]);
         }
         else {
            list($first,$rest) = split("q=", $recent[$x]);
         }
         list($temp,$toss) = split("&", $rest);

         $temp = eregi_replace ("\+", " ", $temp);
         $temp = eregi_replace ("%22", "\"", $temp);
         $temp = eregi_replace ("%27", "'", $temp);
         $temp = eregi_replace ("%26", "&", $temp);
         $temp = eregi_replace ("%20", " ", $temp);
         if (eregi("atomz\.com",$recent[$x])) {
            echo "<b>ls: </b> ";
         }
         else {
            echo "<b>s: </b> ";
         }
         echo "<a href=\"".rtrim($recent[$x])."\">".substr($temp,0,$displaychar - 3);
         if (strlen($temp) > $displaychar - 3) { echo "..."; }
            echo "</a><br />\n";
         }
         else {
            $temp = rtrim(substr((eregi_replace("www\.","",$recent[$x])),7,$displaychar));
            echo "<a href=\"".rtrim($recent[$x])."\">".$temp;
            if (strlen($temp) > $displaychar - 1) { echo "..."; }
            echo "</a><br />\n";
         }
      }
      $recent[$amount] = $HTTP_REFERER."\n";
      if ($HTTP_REFERER && !(eregi($mydomain,$HTTP_REFERER)) &&
          !(eregi("Outpost",$HTTP_REFERER))) {
   $fp = fopen ($recentfile, "w");
   for ($y = $start; $y <= $amount; $y++) {
         fputs($fp, "$recent[$y]");
      }
      fclose ($fp);
   }
?>
Notes:
  • $recentfile should be the full path to the text file that will store your backlinks (it's a good idea to create an empty file by hand and chmod a+w it so that both you and the webserver can write to the file)
  • $mydomain is the domain most of your pages are hosted on, without the leading "www." (ex. laze.net).
  • $displaynum is how many backlinks you wish to display
  • $displaychar is the maximum number of characters to display of the link. The "http://" part will not be shown. Anything beyond the number you set will be replaced with ellipses.
  • && !(eregi("google.com",$HTTP_REFERER)) blocks out any references from google.com. You can change this or remove it. If you want to add other strings (such as your own domain), add another && !(eregi("yourdomain.com",$HTTP_REFERER)) before the final parentheses in the if statement and replace "yourdomain.com" with the string you want to ignore.
  • Note that this isn't anywhere near as fancy as the perl script on Stephen's Web or Disenchanted's Linkback, but perhaps it will be with time. Bookmark this page.
  • If you're using this code in a PHP includes, make sure that you call the includes with its full pathname ("/path/to/includes.php") and not the URL ("http://www.yoursite.com/includes.php"). Otherwise, the HTTP_REFERER will be incorrect.
Release notes:
  • 1.0: Initial release. [26 Jun 02]
  • 1.01: Added a couple rtrims for cleaner code. [27 Jun 02]
  • 1.1: Display is now significantly cleaner. References from search engines show a s: and then the search phrase. References from Atomz show a ls: and the search phrase (referencing "local search"). [10 Jul 02]
  • 1.11: Added MSN to search engines and replacing of "%20" with " ". [16 Jul 02]

Questions? Leave 'em here.

07:39 PM


Comments

I've been using a PHP backlinking script from Laze.Net for a while now to show...

... more

Posted at: The Greedy Capitalist as "Backlink" on January 31, 2004 4:16 AM

I've been using a PHP backlinking script from Laze.Net for a while now to show...

... more

Posted at: The Greedy Capitalist as "Backlink" on January 31, 2004 4:36 AM

I've been using a PHP backlinking script from Laze.Net for a while now to show the referrers to my site. Unfortunately, the script hasn't been updated to reflect changes in Yahoo's new search string. So, I updated the string parsing...

... more

Posted at: Heroic Designs Weblog as "PHP Backlink Script" on January 31, 2004 5:05 AM

Hi
how do I do back links from my site to my site I see this on losts of sites where they are backing linking pages from there own site just to get there google rating up on google .
Thanks Woody.

Posted by: woody on February 23, 2004 11:04 PM

Thanks for the script :-)

We will use it on our free hosting site.

Posted by: Brian on May 22, 2004 5:46 PM

i try it and is cool..
thanks man.
you are genius... :)

Posted by: kostas on May 9, 2007 6:53 AM


Post a comment

Name: (required)

E-mail Address: (required, not published)

URL:

Comments:


Remember info?

You are reading...

... an inidividual entry on twist of fait accomplis, the Official, Authorized, Sanctioned, and Supported Blog of Laze.Net. You might want to go to the front page for more recent goodness or browse through the archives below. Maury loves you.

Archives

Monthly Archives

Special Archives
Blogathon 2001
Blogathon 2002
Funny, True Stories in One Sentence
31 Days, 31 Horror Movies
Erika Sifrit Posts

Powered by Movable Type