Note: I’ll soon be releasing a GUI tool for doing this same task, for those who don’t have Perl installed and would like to have a no-brainer solution.
All right. Many people like to create nifty little PHP Redirects for outgoing affiliate links, or any other kind of link. People have no knowledge about PHP are not comfortable editing a PHP file (even though it’s just one line) because they may mess up on certain things.
I was quite surprised to find some software being sold that does this “PHP Generation.” Well, not really surprised at the software being sold, since not everyone is a programmer, but rather, the limited capability of the software.
You have to generate each link individually, and it wastes such a lot of time. So, I created a Perl script that takes an input file containing slugs and links, and it’ll generate PHP redirect files for all of them in one go. Unfortunately, you need to have Perl installed.
Here’s the script:
#!/usr/bin/perl -w
# Copyright (c) Revolves.Net.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use strict;
use warnings;
my $input = 'affiliatelinks.txt';
my $verbose = 1;
my $template = qq(<?php
header('Location: LOC');
?>);
open INPUT, '<', $input or die('Could not open input file');
foreach my $line (<INPUT>)
{
chomp $line;
my ($slug, $link) = split /\|/, $line;
if ($slug =~ /^#/)
{
print "COMMENTED: $slug\n";
next;
}
unless (open OUTPUT, '>', "goto/$slug.php")
{
print "Could not process: $slug\n";
next;
}
(my $temp = $template) =~ s/LOC/$link/;
print OUTPUT $temp;
close OUTPUT;
print "Processed: $slug\n" if $verbose;
}
This script requires a presence of a file called affiliatelinks.txt. An example file would be (replace xx with tt):
affiliate-link-1|hxxp://affiliatelink1.com affiliate-link-2|hxxp://affiliatelink2.com ... #affiliate-link-n|hxxp://affiliatelink2.com
Using the above text file would cause creation of affiliate-link-1.php and affiliate-link-2.php each redirecting to affiliatelink1.com and affiliatelink2.com respectively. The “slug” and the “link” are seperated by the pipe character (|) above your Enter key. There should be no space on either side of the pipe character. Lines starting with ‘#’ are ignored.
Using the script
Put the Perl script (let’s call it affgen.pl) in a folder, and create ‘affiliatelinks.txt’ in that same folder. Fill the text file as instructed above. Open the command line and navigate to the script’s folder, and type:
perl affgen.pl
Or you can simple double click on the affgen.pl file if you have something like ActivePerl installed. This would create a folder called goto which would contain all the PHP files. Upload these files to a desired folder on your server. Always test the links to see if they work!
If you have any problems, post a comment below and I’ll get back to you.

No Comments so far ↓
There are no comments yet...Kick things off by filling out the form below.