Code Snippets

You can easily create dereferring links using the generator at our homepage. The code snippets on this page might be of interest, if you run a dynamic web page like a forum, a blog or something similar. Please don't hesitate to send further helpful code examples! They will be added to this site.

PHP implementation
JavaScript implementation
phpBB 2 modification
phpBB 3 custom BBCode

PHP Implementation

This code snippet shows how to define a function that prints the dereferring link for a given URL, i.e. for a given internet address, and how it can be used in combination with a html link. <?php function derefer ($url) { print 'http://derefer.me/?' . urlencode ($url); } ?> <a href="<?php derefer ('http://example.com/'); ?>">Example</a>

Base64-Encoded Version

<?php function base64_derefer ($url) { print 'http://base64.derefer.me/?' . urlencode (base64_encode ($url)); } ?> <a href="<?php base64_derefer ('http://example.com/'); ?>">Example</a> See our frequently asked questions for more information on base64-encoding.

JavaScript Implementation

This snippet shows how one can derefer links with JavaScript. Attention! Website owners should not rely on simple JavaScript solutions, as some users might have deactivated JavaScript. The link would not be dereferred then and your site would appear in the log files of the target page. The more users you have, the higher the chances that your site appears as referer in other websites' log files. <script type="application/javascript"> function derefer (url) { window.location.href = 'http://derefer.me/?' + encodeURIComponent (url); return false; } </script> <a href="http://example.com/" onclick="return derefer (this.href);">Example</a>

phpBB 2 Modification

An easy phpBB 2 modification which derefers all user posted links can be downloaded here: phpBB 2 modification. The current version is 1.2.1. Updates from prior versions are available:
update 1.0.0 to 1.2.1
update 1.1.0 to 1.2.1
update 1.2.0 to 1.2.1

phpBB 3 Custom BBCode

phpBB 3 "Olympus" offers the possibility to add custom BBCodes. Here is an easy five minutes tutorial on how to configure such an additional BBCode which derefers links. While it works best with JavaScript it derefers every link even with JavaScript deactivated.

Login with your admin account, go to the Administration Control Panel, choose tab Posting and select BBCode, if not pre-selected already. Click on Add a new BBCode. Fill out the form as follows:

BBCode usage [derefer={URL}]{TEXT}[/derefer] HTML replacement <a href="http://derefer.me/?{URL}" onclick=" window.location.href = 'http://derefer.me/?' + encodeURIComponent('{URL}'); return false; ">{TEXT}</a> Help line Derefer URL: [derefer]http://url[/derefer] or [derefer=http://url]URL text[/derefer] Check the box Display on posting page. Click on Submit and you have created a first custom BBCode. Now add a second one, which is actually just a simple version of the BBCode above. This is in analogy with phpBB's native URL-BBCode which comes in two versions as well. Proceed as described above but fill out the form as follows:

BBCode usage [derefer]{URL}[/derefer] HTML replacement <a href="http://derefer.me/?{URL}" onclick=" window.location.href = 'http://derefer.me/?' + encodeURIComponent('{URL}'); return false; ">{URL}</a> Leave the Help line blank, leave the Display on posting page unchecked and click on Submit.

Congratulations! You have added a derefer-BBCode to your board which works like the URL-BBCode besides also dereferring the link.

 
 

© 2008–2012 derefer.me