Jump to content

link cloaking help


simcoweb

Recommended Posts

I'm trying to write a simple 'cloaking' script that works like a 'jump' where I can use it instead of the actual affiliate link to prevent the typical link bypassers from simply mousing over and going directly. Here's what I have so far:

 

<?php
if($m == "") ($link = "http://www.templateresources.com"); // Default URL
if($m == "Premium Flash Templates") ($link = "http://store.templatemonster.com/?aff=simco"); //Template Monster
if($m == "Free CSS Templates") ($link = "http://www.templateworld.com/3091.html"); // Template World

header("Location: $link"); // Jump to the hidden affiliate URL above
exit();
?>

 

Then using a hyperlink structure like this:

jump.php?m=Free CSS Templates

 

But when clicking on any of the links it goes to the default (1st one) instead of the designated one. Ideas?

Link to comment
Share on other sites

<?php
$m = isset($_GET['m']) ? $_GET['m'] : NULL;
switch($m)
{
  case 'Free CSS Templates':
    $link = "http://www.templateworld.com/3091.html";
    break;
  case 'Premium Flash Templates':
    $link = "http://store.templatemonster.com/?aff=simco";
    break;
  // as many other cases as you need

  default:
    $link = "http://www.templateresources.com";
}

header('Location: ' . $link);
exit;
?>

Link to comment
Share on other sites

I'd recommend using a different type of system so you don't need to manually add in all the links you want to do that to.

 

I personally use base64 encoding of my urls, and send them a link.php page with the encoded url. Then I decode and use a header to redirect. It's easy and clean, and has the same affect.

Link to comment
Share on other sites

Thanks to all for the replies!

 

Zhadus, can you give me an example of what you're referring to? It would be marvelous if I didn't have to manually insert the links since the sheer number of links could exceed 100. If there's a way to write these to a file that is read and then cloaked... is that what you're referring to?

Link to comment
Share on other sites

I agree with Ken2k7 that a database would be optimal, but this saves on queries to the database, and there are very few people who would rather decode a URL than just click the link. Here are the two functions I use:

 

function getLink($matches)
{
if (preg_match('/^www\./', $matches[2]))
	$link = 'http://' . $matches[2];
else
	$link = $matches[2];
$link = base64_encode($link);
$result = $matches[1] . 'link.php?url=' . $link. $matches[3];

return $result;
}

function linkMask($text)
{
$pattern = '/(<a href=["|\'])(.*?)?(["|\']>)/';
$text = preg_replace_callback($pattern, "getLink", $text);

return $text;
}

 

I can't guarantee it's bug free. You'll want to run whatever text you have through the linkMask() function and it will do the rest. It also fixes links incase you mistakenly type www.blah.com instead of using the http://. To use it, the links are just in normal "a href" format that it checks for.

 

On my link.php page, it looks like this:

$target = base64_decode($_GET['url']);
header ("Location: $target");

 

Mine has a lot more features, but that's the basic jist and I think you're knowledgeable to modify it to your needs.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.