Well, this was an idea from Kuntal Gupta. He asked me to make a redirecting script, so that if you pass any url to that page, it'll redirect to that link surely, but will also give your site a hit. Then i just thought, why not use JS to turn all the hyperlinks to such redirecting links. That way, whenever someone clicks a link on your site, you get an extra hit, irrespective of  if the link is outgoing or in your site. :D This is how it works - Make a php file, name it redirect.php and save it in your root so that the location is, say, http://<your_url>/redirect.php and then edit the file and paste this code -
<?php
   $url=$_REQUEST['url'];
   header("location: $url");
?>
Save it. Now add this Javascript snippet in your site's header, inside the <head></head> block -
<script type="text/javascript" language="javascript">
function reDirectMe() {
  var link = document.getElementsByTagName("a");
    for (var i=0;i<link.length;i++)
        {
            link[i].href = "http://<your_url>/redirect.php?url="+link[i].href;
        }
}
window.onload=reDirectMe;
</script>
Now obviously you'd like to change the <your_url> part to your domain. And thats it. Now reload your site, and you'll see that all your hyperlinks have changed and now passes through the redirect.php file and gives you an extra hit every time you click a link. Enjoy. :D

Bibhas Debnath

iambibhas bibhasdn


Published

blog comments powered by Disqus