hey bitches, it's time I give something back to WF, here's the code I use to cloak affiliate links
basically it works this way:
there's a database table where you put all your affiliate links and the codes you want to use in place of the real link
there's a small php script that runs the query and pushes the visitor to the affiliate site
I use an .htaccess file to mask everything so I can use links like mydomain.com/bluebananas and the visitor will be pushed to my affiliate bluebananas merchant
I don't know if this works on windows servers but it should as long as it's running apache
in case your server runs on IIS I don'tknow if you'll be able to use the cool sexy links but the script will work anyway: you'll just need to make your links to go.php?d=bluebananas
first thing open phpmyadmin, create a database and past this into the SQL box
this creates the table
let's see the .htaccess file
it takes anything after the domain and rewrites it as a variable for the php script
example: mydomain.com/bluebananas becomes mydomain.com/go.php?d=bluebananas
now, this is the php file that will actually push the visitor to the affiliate link
it takes the parameter and runs a query retrieving the real affiliate link, then refreshes the visitor's browser to that link
if, for any reason, the query doesn't return any link the visitor is sent back to the home page
to add my affiliate links I go directly through phpmyadmin, it's just 2 fields, not worth spending time writing a page to do that (although I have something that might almost fit sitting in some corner of my hard disk)
basically it works this way:
there's a database table where you put all your affiliate links and the codes you want to use in place of the real link
there's a small php script that runs the query and pushes the visitor to the affiliate site
I use an .htaccess file to mask everything so I can use links like mydomain.com/bluebananas and the visitor will be pushed to my affiliate bluebananas merchant
I don't know if this works on windows servers but it should as long as it's running apache
in case your server runs on IIS I don'tknow if you'll be able to use the cool sexy links but the script will work anyway: you'll just need to make your links to go.php?d=bluebananas
first thing open phpmyadmin, create a database and past this into the SQL box
Code:
CREATE TABLE `links` (
`id` int(4) NOT NULL auto_increment,
`code` varchar(20) NOT NULL default '',
`url` varchar(200) NOT NULL default '',
`visits` int(11) NOT NULL default '0',
PRIMARY KEY (`code`),
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM
let's see the .htaccess file
Code:
<Files .htaccess>
Order allow,deny
Deny from all
</Files>
Options -Indexes +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([-a-z0-9_]+)/?$ go.php?d=$1 [NC,L]
example: mydomain.com/bluebananas becomes mydomain.com/go.php?d=bluebananas
now, this is the php file that will actually push the visitor to the affiliate link
Code:
<?php
$connect = mysql_connect(localhost,dbusername,dbpassword) or die("Error connecting to Database! " . mysql_error());
mysql_select_db(dbname , $connect) or die("Cannot select database! " . mysql_error());
if (isset($_GET['d']))
{
$dest = $_GET['d'];
$query = mysql_query("SELECT url FROM links where code='$dest' LIMIT 1") or die(mysql_error());
$count = mysql_query("UPDATE links SET visits = visits + 1 WHERE code='$dest'") or die(mysql_error());
while ($row = mysql_fetch_object($query))
header("Refresh: 0; url=".$row->url);
}
else
{
header('Refresh: 0; url=http://www.mydomain.com');
}
?>
if, for any reason, the query doesn't return any link the visitor is sent back to the home page
to add my affiliate links I go directly through phpmyadmin, it's just 2 fields, not worth spending time writing a page to do that (although I have something that might almost fit sitting in some corner of my hard disk)