Apolva
12-04-2010, 12:10 PM
OK so I got a little frustrated with all these stupid surveys just to see a "funny" picture, so I've written a simple php script to block them.
Note: this was done in a hurry, I know it's wildly inefficient and doesn't translate relative -> absolute URLs, it's merely POC.
I tested it, and it seemed to work fine without translating the URLs, but feel free to make improvements...
Explanation:
OK, so CPAlead is the people who provide the surveys. What happens is the page downloads their script containing the ads, then makes sure that it has been downloaded (else will show a "disable your ad-blocker warning").
This script changes the address of the survey script to itself, tricking the rest of the script into thinking the surveys have been loaded.
Source:
<?php
$u=$_GET['u']; // URL
// Show the fake survey script page.
if($_GET['divert']=="y"){header("Content-type: text/js"); die("isloaded=true");}
// If no URL is present, show the form.
if($u=="") die("<div style='text-align:center;margin-top:30px;margin-bottom:10px;'>This is just to bypass those annoying "answer the survey to see the pic" sites.</div><form><table style='margin:0 auto;'><tr><td><b>URL:</b></td><td><input type='text' value='http://' name='u' style='width:200px;' /></td></tr><tr><td colspan='2' style='text-align:center;'><input type='submit' value='Go »' /></td></tr></table></form>");
// Blocks local file acess.
if(substr($u,0,7)!="http://" && substr($u,0,8)!="https://") die("<b>Error</b> - Not a valid site address.");
// Get remote page.
$file=@file_get_contents($u);
if(!$file) die("<b>Error</b> - Can't access the site.");
// To prevent it just being used as a proxy.
if(strpos($file,"http://www.cpalead.com/")===FALSE){die("<b>Error</b> - Site hasn't got a survey on it.");}
// Rewrite the script url to use fake one.
$file=str_replace("http://www.cpal"."ead.com/mygateway.php?","?divert=y&",$file);
// Output page.
echo $file;
?>
I'm not hosting this myself because I know someone will come and abuse it and probably get my hosting suspended, lol.
If someone does decide to use it, a little credit doesn't harm. :)
Note: this was done in a hurry, I know it's wildly inefficient and doesn't translate relative -> absolute URLs, it's merely POC.
I tested it, and it seemed to work fine without translating the URLs, but feel free to make improvements...
Explanation:
OK, so CPAlead is the people who provide the surveys. What happens is the page downloads their script containing the ads, then makes sure that it has been downloaded (else will show a "disable your ad-blocker warning").
This script changes the address of the survey script to itself, tricking the rest of the script into thinking the surveys have been loaded.
Source:
<?php
$u=$_GET['u']; // URL
// Show the fake survey script page.
if($_GET['divert']=="y"){header("Content-type: text/js"); die("isloaded=true");}
// If no URL is present, show the form.
if($u=="") die("<div style='text-align:center;margin-top:30px;margin-bottom:10px;'>This is just to bypass those annoying "answer the survey to see the pic" sites.</div><form><table style='margin:0 auto;'><tr><td><b>URL:</b></td><td><input type='text' value='http://' name='u' style='width:200px;' /></td></tr><tr><td colspan='2' style='text-align:center;'><input type='submit' value='Go »' /></td></tr></table></form>");
// Blocks local file acess.
if(substr($u,0,7)!="http://" && substr($u,0,8)!="https://") die("<b>Error</b> - Not a valid site address.");
// Get remote page.
$file=@file_get_contents($u);
if(!$file) die("<b>Error</b> - Can't access the site.");
// To prevent it just being used as a proxy.
if(strpos($file,"http://www.cpalead.com/")===FALSE){die("<b>Error</b> - Site hasn't got a survey on it.");}
// Rewrite the script url to use fake one.
$file=str_replace("http://www.cpal"."ead.com/mygateway.php?","?divert=y&",$file);
// Output page.
echo $file;
?>
I'm not hosting this myself because I know someone will come and abuse it and probably get my hosting suspended, lol.
If someone does decide to use it, a little credit doesn't harm. :)