Backlinks or referrers script (php and mysql)
Last script update: 19 August 2002 - pretty big code face-lift. got rid of wget.
This page isn't a very good explanation of what the script does and what backlinks are. I'll probably re-write it more in detail in a few weeks/months/years. In the meantime, if you're curious, just ask! (Send me a mail if you're using the script and want me to keep you informed of fixes.)
This script allows you to "backlink" to pages which link to each of your pages. It stores all "valid" referrers in a database table, and writes out a list of referrers (by popularity) on each page it is included in. You can see it at work at the bottom of the left column on each page of this site.
It also lists google search requests for each page.
This script is aimed at reasonably proficient users. You will have to build the database yourself and edit some of the php code to get it working for you. This is not a definitive tutorial - it is just a few notes to accompany the publication of the messy code and help you find your way through it.
Suggestions for improvement, bug reports and comments are of course welcome. It's not quite finished yet - check for updates.
A big thanks to everybody who helped me debug my mysql queries and get my php code straight!
Source Code and Some Explanation
First, download these three files:
The code is more or less commented, and the parts you need to edit are marked out. Rename the files "referrers.php", "backlinks.php", "google_search.php".
Then, create two tables in a database: "referrers" and "titles". Actually, I've dumped the table structure for you now
.For "referrers", you want the following fields: a primary key (I called it ref_key and set it to autoincrement), page, referrer, ip (all of these varchar, I fixed the length of the two first ones to 150), datetime (a "datetime" field) - and a delete_flag, you never know (enum('0','1')). The only fields the script calls are page, referrer, ip, and datetime.
The table "titles" just contains page titles for each referrer. This allows to list the referrers by their name and not by their uri. In addition to a primary key, you'll need two varchar fieds: referrer and title.
The "titles" function should be working now. In any case, you can enter titles in the database manually.
I include the "referrers" part of the script near the top of all my pages (so that partial loads are taken into account), and I include the "backlinks" part where I want the backlinks code to be produced... You'll also see there is a reference to a commentPopUp javascript function in the backlinks.php code - you can find that function in the source code of any page on my site.
Have fun, and check out similar scripts listed on IAWiki.



