roll your own del.icio.us (sort of)

For some reason the thought of using del.icio.us doesn’t appeal to me (maybe it’s my super secret pr0n links that I don’t want public biggrin roll your own del.icio.us (sort of) lol) but I would like to be able to have access my links where ever I am. I’ve been on the road too many times, trying to get some work done, when I could have used a link or to. So, I thought I’d roll my own since I’ve got this web space and all.

The bookmarklet itself is very easy to understand:

javascript:location.href='http://www.shindakun.net/supaleethiddendir/
bookmarklet.php?url='+encodeURIComponent(location.href)+'&title='
+encodeURIComponent(document.title)+'&extended='
+escape(document.getSelection())

By setting that code as a link in Firefox I can add any link to my bookmarklet database. The database simply contains a link id number, the date the link was made, the page URL, the page title and if I highlight a bit of text on the page before clicking the bookmarklet – it will include that also.

[WARNING]As it is the code does no input checking – that is why the php is put into a ‘hidden’ directory. It’s possible someone could do some crafty SQL tricks. Remember to verify any data before inserting it into your database.[/WARNING]

I’m just lazy right now – and no one would ever find the script on my server so there. bigrazz roll your own del.icio.us (sort of) Anyway, on the server side the code for bookmarklet.php is where all of the ‘hard work’ takes place.

//bookmarklet.php - 11/15/05 - steve@shindakun.net

function dbconnect() {
global $sqlUsername, $sqlHostname, $sqlPassword, $sqlDatabase;

$dbcnx = @mysql_connect($sqlHostname, $sqlUsername, $sqlPassword);

if (!$dbcnx) {
echo( "Unable to connect to the database server at this time.

" );
exit();  }

if (! @mysql_select_db( $sqlDatabase ) ) {
echo( "

Unable to locate the database $string at this time.

" );
exit();  }
}

if (isset($_GET['url']) && isset($_GET['title'])){

dbconnect();

$url = $_GET['url'];
$title = $_GET['title'];
$extended = $_GET['extended'];
//no security - for shame!
$do_change  = mysql_query("INSERT INTO bookmarklet SET
date=NOW(),url='$url',title='$title',extended='$extended'");

?>
<script language="JavaScript">
<!--//hiding it
history.back();
//end hiding it-->
</script>
<?
}

else {

?>
<script language="JavaScript">
<!--//hiding it
history.back();
//end hiding it-->
</script>
<?
}
?>

When loaded bookmarklet.php first checks to see if the URL and TITLE variables have been set. If they have the it connects to a MySQL database and inserts our bookmark. Once done it drops back to the you bookmarked. If the URL and TITLE variables aren’t set then it simply drops back to the page you bookmarked.

Maybe tomorrow I’ll go over how to display your new links. *yawn* G’dnight.

*edit* small opps on the code. It’s fixed.

Bookmark and Share
If you enjoyed this post, make sure you subscribe to my RSS Feed


Related Posts:
Here come the zombies!
Xbox 360 HDD Saga Continues
A Foot In The Door Part III
TOSEC and TIM
Finished The Fight

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment