Skip to content

Instantly share code, notes, and snippets.

@allen501pc
Created May 5, 2012 07:27
Show Gist options
  • Save allen501pc/2600630 to your computer and use it in GitHub Desktop.
Save allen501pc/2600630 to your computer and use it in GitHub Desktop.
[PHP] Url encryptor
<?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