|
|
|
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);
?> | | |
|
| 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 | | | Pull deliniated text strings into a "SELECT" statement in a form. Categories : HTML and PHP, PHP, Strings | | | Wraps a HTML(!) string to a given number of characters using a string break character Categories : PHP, Strings, HTML and PHP | | | Produces browser-safe strings while preserving HTML tags. Categories : Strings, HTTP, PHP, HTML and PHP | | | Text Wrapping Categories : PHP, HTML and PHP, Strings | | | string justification align center text Categories : Strings, PHP, HTML and PHP | | | 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 | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | Alternating background color for HTML table rows Categories : PHP, Databases, MySQL, HTML and PHP | | | Constantly refresh your PHP/HTML page data. Categories : PHP, HTML and PHP, Sybase | | | Select with current month Categories : PHP, HTML and PHP, Date Time, Arrays | | | background music script for random notes in a frame Categories : PHP, Content Management, HTML and PHP | |
|
|
|