Encryption

It is a concept of Encoding and Decoding the data. Basically, we have two types of Encryption in PHP. Those are

  1. One_way Encryption
  2. Two_way Encryption

One_way Encryption:

By using this, we can encode the data but we cannot decode encoded data.

1. md5() function: (Message-Digest 5)

By using this function, we can encode the data as 32 characters length, alphanumeric string.

Syntax

snippet
string md5 ( string $str [, bool $raw_output = FALSE ] )

Parameters

Parameter Description Is compulsory
String The string to be calculated. compulsory
raw_output Specifies hex or binary output format:
TRUE- Raw 16 character
FALSE- Default.
Optional

Returns

md5() function returns the calculated md5 hash on success, or false on failure.

Example 1

snippet
<?php 
	$str = "sonoo";
	echo md5($str);
?>

Output:

Encryption

Example 2

snippet
<?php
$str = "sonoo";
echo md5($str);
if (md5($str) == "ea866df636e6d5b4b7c9ab7b596cdd4c")
  	{
  		echo "<br>Hello rookienerd";
 		 exit;
 	 }
?>

Output:

Encryption
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +