URL freindly key based encryption

Many of PHP developers will need this in their scripts. This code snippet make utilization of mcrypt. It encodes the data and then take base64 of it and then removes the characters returned by base64 that does not fit into URL.

function encrypt($text, $salt) {

return strtr(rtrim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $salt, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))), '='), '+/', '-_');
}
function decrypt($text, salt) {

return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $salt, base64_decode(strtr($text, '-_', '+/')), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
}
read more

SQL Injection Cheatsheet

There are so many people who are looking for some quick details on this subject. I came across this very much interesting writing while browsing the Internet and reading various blogs online. I think the writer shows a lot of ways to find security holes in SQL. It is also very much useful for programmers to block such holes from their code. Please read it here.
read more

URL Shortening code snippet

Last day I was wondering how goog.gl shortens URLs to 4 characters only. After doing some research I came up with following algorithm that produces URL short codes in incremental format. Incremental means: It will first give 1 character based URLs, once all possible URLs of 1 character are taken then it will give 2 characters based and then 3 and son on. $number is an incremental number that you can save somewhere in your database or a text file. It will start from 1 and will keep on getting incremented by 1 with every new URL generation. Here is a quick function for this purpose: function generate_url_code($number)...
read more