Created
May 5, 2012 07:27
-
-
Save allen501pc/2600630 to your computer and use it in GitHub Desktop.
[PHP] Url encryptor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Function: ImageURLEncryption | |
* Parameters: | |
* $Url : the url or text that you want to encrypt. | |
* $Code: the magic code which masks the url. | |
*/ | |
function ImageURLEncryption($Url,$Code) | |
{ | |
$SecretCode = md5($Code); | |
$StringLength = strlen($Url); | |
$SecretCodeLength = strlen($SecretCode); | |
for( $Index =$StringLength %2; $Index < $StringLength; $Index+=2) | |
{ | |
$Url[$Index] = chr(ord($Url[$Index])^ord($SecretCode[$Index%$SecretCodeLength])); | |
} | |
$Url = base64_encode($Url); | |
return $Url; | |
} | |
/* Function: ImageURLDecryption | |
* Parameters: | |
* $EncryptedUrl : the encrypted url or text that you want to decrypt. | |
* $Code: the magic code which unmasks the url. | |
*/ | |
function ImageURLDecryption($EncryptedUrlCode,$Code) | |
{ | |
$SecretCode = md5($Code); | |
$EncryptedUrlCode=base64_decode($EncryptedUrlCode); | |
$SecretCodeLength = strlen($SecretCode); | |
$StringLength = strlen($EncryptedUrlCode); | |
for($Index = $StringLength %2; $Index < $StringLength; $Index +=2) | |
{ | |
$EncryptedUrlCode[$Index] = chr(ord($EncryptedUrlCode[$Index])^ord($SecretCode[$Index%$SecretCodeLength])); | |
} | |
return $EncryptedUrlCode; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment