WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Customizable encoding and decoding strings with security.
Categories : PHP, Strings, HTML and PHP Click here to Update Your Picture
Mian Shafiq ur Rehman
Date : Dec 16th 2004
Grade : 3 of 5 (graded 9 times)
Viewed : 5062
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Mian Shafiq ur Rehman
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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