Simple bookmark manager in 20 lines of PHP.

By kyusl

There are dozens of bookmarks managers on the Web, but for my most simple needs, I decided to make my own. I have bookmarks at Yahoo, but do use them efficiently, I have to install their Toolbar, and you can never know what does it do with your private infomation. Del.icio.us is good too, but the default setting is that your bookmarks are public (well, it’s the main idea of the service actually). So, there are no ideal services, and tired of keeping different sets of bookmarks on my home and office computers, I implemented a very rudimentary but my own bookmarks storage script. It takes less than twenty lines of PHP but it does what I need. To use it, you have to have your own PHP-capable site on the Web (even a free one should work). It’s important to note that there are no login checks and the only way to prevent the owner from troubles is to use some cryptic file names (instead of ones below). “Troubles” means not making your private bookmarks public (which is not good too), but allowing anyone to post there, which can be used to plant some nasty Javascript into your file to hack your browser.

The principle is very simple. If you supply at least the URL parameter, it adds a new bookmark and then displays the whole list. If no URL parameter is given – it’s just the display. To make things easier, you have to create a bookmark in your browser with the following Javascript instead of usual URL (note that there is no http:// stuff, and don’t forget to replace localhost and bm.php with your own host and file names):

javascript:location.href=’http://localhost/bm/bm.php?url=’+encodeURIComponent(location.href)+’&title=’+encodeURIComponent(document.title)

The PHP code is below. Normally, WordPress screws up the quote symbols (both single and double), so you have to retype them. To prevent warnings on the first use, either create the include file or try it right with adding a bookmark.


<?
print '<html><title>Bookmarks</title><body>Bookmarks<br><br><br>';

if( isset($_GET['url']) ) {
$url = $_GET['url'];
$title = ”;
if( isset($_GET['title']) ) $title = $_GET['title'];
if( $title == ” ) $title = $url;
$handle = fopen(“bm.inc”, “a”);
fwrite($handle, ‘<a href=”‘.$url.’”>’.$title.’<br>’);
fclose($handle);
}

include ‘bm.inc’;

print ‘</body></html>’;

?>

Obviously, it's not a full manager because there are no edit or delete features. But as I almost never to that, it's fine with me to edit the file directly when needed.

Leave a Reply