simcoweb Posted May 27, 2009 Share Posted May 27, 2009 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? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 How did you define the variable $m? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted May 27, 2009 Share Posted May 27, 2009 <?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; ?> Quote Link to comment Share on other sites More sharing options...
Zhadus Posted May 27, 2009 Share Posted May 27, 2009 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. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted May 27, 2009 Author Share Posted May 27, 2009 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? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 Zhadus just wants to encode the URL parameter passed. A better method would be to utilize a database. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted May 27, 2009 Author Share Posted May 27, 2009 Ok, then the database could assign an id to the link and do something like jump.php?id=10 or similar? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 Something like that. Quote Link to comment Share on other sites More sharing options...
Zhadus Posted May 27, 2009 Share Posted May 27, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.