WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : 10940
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  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);
?>



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