The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 22, 2019, 07:46:23 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: handy script to hide your affiliate urls  (Read 2955 times)
NYDAz
Expert
****
Offline Offline

Posts: 212

The Night Stalker


View Profile
« on: September 16, 2009, 10:46:31 AM »

Well ... since I've learned alot here ... I want to contribute with something ...

It's not a complex or big tool ... but it's very handy ... to hide your affiliate urls

Please note that I'm a begginer in PHP so don't blame me  Roll Eyes

buy.php
Code:
<?PHP
$daz = $_GET['daz'];

// FIRST AFFILIATE LINKS
if ($daz == "1") {$link = "http://www.youraffiliateurl.com/&id=111111111";}
if ($daz == "2") {$link = "http://www.youraffiliateurl.com/&id=111111111";}
if ($daz == "3") {$link = "http://www.youraffiliateurl.com/&id=111111111";}
// you can put a lot of links just rember to change the number

// SECOND AFFILIATE LINKS
if ($daz == "4") {$link = "http://www.youraffiliateurl.com/&id=111111111";}
if ($daz == "5") {$link = "http://www.youraffiliateurl.com/&id=111111111";}
if ($daz == "6") {$link = "http://www.youraffiliateurl.com/&id=111111111";}
// you can put a lot of links just rember to change the number

header("Location: $link");
exit();
?>

And the links should be executed like this : http://www.example.com/buy.php?daz=6

 Smiley
Logged

what's up?
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #1 on: September 16, 2009, 11:20:52 AM »

not bad for beginning. However, imagine now having thousands of aff links.

Another option is to encode the destination URL somehow.
For example, just encrypt it. then decrypt to redirect.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
NYDAz
Expert
****
Offline Offline

Posts: 212

The Night Stalker


View Profile
« Reply #2 on: September 16, 2009, 11:25:10 AM »

can u give me an example nutt ?
Logged

what's up?
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #3 on: September 16, 2009, 12:11:41 PM »

At the simplest level, you could base64 encode.
So...

to create a link in your page you would spit it out from php as something like:
echo '<a href="?id='.base64_encode('http://www.amazon.com/gp/bestsellers/').'">Buy this shit</a>';
which will spit out:
<a href="?id=aHR0cDovL3d3dy5hbWF6b24uY29tL2dwL2Jlc3RzZWxsZXJzLw==">Buy this shit[/url]

Clicking that link of course just drops you back on the same page with an id in the getstring now.
so... to redirect:
header("Location: ".base64_decode($_GET['id']));

note, this is not secure at all. Since afterall, anyone can decode a base64 string, and therefor, could use your site for forwarding redirects. but you get the idea.
for more advanced stuff, you have mcrypt_encrypt and mcrypt_decrypt. but those will make your head hurt.


I did just realize though that you might not be pulling this stuff from a database. I guess really the way you did it is just as good technically in that case. And if you did use a database, you could just store the affiliate URL in there, and lookup by a numeric ID like you have in $das.

So i probably overthought your post. lol big surprise. (perk just rolled his eyes im sure)
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
kurdt
Lifer
*****
Offline Offline

Posts: 1153


paha arkkitehti


View Profile
« Reply #4 on: September 16, 2009, 12:31:07 PM »

I think it's a bit neater code if you do it this way:
Code:
switch ($_GET['daz']) {
case '1': $link = "http://www.perksdbporn.com/?aff=69"; break;
        case '2': $link = "http://www.perksdbporn.com/?aff=69"; break;
default: $link = "http://www.google.com"; break;
}
header("Location: ".$link);
Logged

I met god and he had nothing to say to me.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #5 on: September 16, 2009, 12:42:26 PM »

Another option:


$arr
[] = 'http://www.google.com';
$arr[] = 'http://www.perksdbporn.com/?aff=69';
$arr[] = 'http://www.coolporn.com/?aff=21A';
$arr[] = 'http://www.moreporn.com/?aff=110101';

header("Location: {$arr[$_GET['daz'] - 0]}");


Note the quick and dirty HTTP injection protection ( - 0 ) which also will force the zeroth array element to be selected if the $_GET parameter is not found. But to get the maximum benefit from this you'd want to be using APC or a compiler cache so that you don't have to recompile the array again. I've also been known to make huge arrays from DB tables, then serialize them, then include them as precompiled code as well. quick quick quick. If you only have a few URLs then it's no trouble to switch it: when you get into lots of options for the switch an array will be faster and easier to work with in code.
« Last Edit: September 16, 2009, 12:44:26 PM by perkiset » Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
NYDAz
Expert
****
Offline Offline

Posts: 212

The Night Stalker


View Profile
« Reply #6 on: September 16, 2009, 01:57:12 PM »

Good advices ... always a pleasure to hear from you guys

 Applause
Logged

what's up?
serialnoob
Journeyman
***
Offline Offline

Posts: 88


View Profile
« Reply #7 on: November 11, 2009, 06:06:42 PM »

I've also been known to make huge arrays from DB tables, then serialize them, then include them as precompiled code as well. quick quick quick.

That's the way I do it basically because on shared hosts, apc is not always available, but

1- could clarify how huge you went? ie what is a huge array in such case.

2- serialize ? do you mean as in : unserialize(hxxp://blabla?echo(serilized(yourdbqueryresult))  ?
Logged

Success consists of going from failure to failure without loss of enthusiasm - Winston Churchill
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!