Title : Customizable encoding and decoding strings with security.
Version: 1.0.0
Author: Mian Shafiq-ur-Rehman
Email : gurru@phpgurru.com
Mess : rehmanms@hotmail.com
Website: www.phpgurru.com
I have written two functions to encode and decode strings. This is very useful for setting username / passwords in cookies. The main advantage of encode function is that it generates different encoded string every time but decode function decode
the encoded string very intelligently. This will increase your security level of cookies data.
<?php
function encode ( $originalStr )
{
$encodedStr = $originalStr ;
$num = mt_rand ( 1 , 6 );
for( $i = 1 ; $i <= $num ; $i ++)
{
$encodedStr = base64_encode ( $encodedStr );
}
$seed_array = array( 'S' , 'H' , 'A' , 'F' , 'I' , 'Q' );
$encodedStr = $encodedStr . "+" . $seed_array [ $num ];
$encodedStr = base64_encode ( $encodedStr );
return $encodedStr ;
}
function decode ( $decodedStr )
{
$seed_array = array( 'S' , 'H' , 'A' , 'F' , 'I' , 'Q' );
$decoded = base64_decode ( $decodedStr );
list( $decoded , $letter ) = split ( "\+" , $decoded );
for( $i = 0 ; $i < count ( $seed_array ); $i ++)
{
if( $seed_array [ $i ] == $letter )
break;
}
for( $j = 1 ; $j <= $i ; $j ++)
{
$decoded = base64_decode ( $decoded );
}
return $decoded ;
}
?>
Usage Example
<?php
$orgStr = "www.phpgurru.com" ;
$decodedStr = encode ( $orgStr );
echo $decodedStr ;
// this will output a long string like V2tST2EwMHdlSFZSYlRscVVqSlJlRmt5TlV0TlZYaDBWRzVhYVZWVU1Eaz0rRg==
// This will output the original string www.phpgurru.com
echo decode ( $decodedStr );
?>
PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP , Email , PHP , Perl , HTML and PHP Parse string to find sub-string between two arbitrary strings Categories : PHP , Strings , HTML and PHP , Arrays Pull deliniated text strings into a "SELECT" statement in a form. Categories : HTML and PHP , PHP , Strings function textwrap will wrap text to any desired width using <BR>\n as the default line break.
Default wrap width is 80 columns.
Categories : Strings , HTML and PHP , PHP Wraps a HTML(!) string to a given number of characters using a string break character Categories : PHP , Strings , HTML and PHP string justification align center text Categories : Strings , PHP , HTML and PHP Text Wrapping Categories : PHP , HTML and PHP , Strings Produces browser-safe strings while preserving HTML tags. Categories : Strings , HTTP , PHP , HTML and PHP Filter - A simple class that lets you use multiple functions to create custom filters. Categories : PHP , PHP Classes , Strings Amazon book cover handling Categories : HTML and PHP , PHP , MySQL , Ecommerce Variable serialization and unserialization. Loading and saving variable structures
to and from file. Categories : Arrays , Filesystem , Variables , Strings , PHP Football News Aggregator Categories : PHP , Object Oriented , PHP Classes , Rich Site Summary (RSS) , HTML and PHP Dynamic form field Categories : PHP , HTML and PHP , Form Processing Customizable Calendar Class Categories : HTML and PHP , Date Time , PHP , PHP Classes , Calendar Website Engine Categories : PHP , HTML and PHP , Templates