URL address transfer encryption and decryption function in PHP development

Source: Internet
Author: User
Tags decrypt vars

functionKeyED ($txt,$encrypt _key)//define a keyed{             $encrypt _key=MD5($encrypt _key); $ctr=0; $tmp= ' ';  for($i= 0;$i<strlen($txt);$i++)             {                     if($ctr==strlen($encrypt _key))          $ctr=0; $tmp.=substr($txt,$i, 1) ^substr($encrypt _key,$ctr, 1); $ctr++; }             return $tmp; }      functionEncrypt$txt,$key)     {      $encrypt _key=MD5(Mt_rand(0,100)); $ctr=0; $tmp= ' ';  for($i= 0;$i<strlen($txt);$i++)              {          if($ctr==strlen($encrypt _key))              $ctr=0; $tmp.=substr($encrypt _key,$ctr, 1). (substr($txt,$i, 1) ^substr($encrypt _key,$ctr, 1)); $ctr++; }              returnKeyED ($tmp,$key); }      functionDecrypt$txt,$key)  {             $txt= KeyED ($txt,$key); $tmp= ' ';  for($i= 0;$i<strlen($txt);$i++)             {                     $MD 5=substr($txt,$i, 1); $i++; $tmp.= (substr($txt,$i, 1) ^$MD 5); }             return $tmp; }//Encrypt URL parametersfunctionEncrypt_url ($url,$key)  {      return Rawurlencode(Base64_encode(Encrypt ($url,$key))); }//Decrypting URL ParametersfunctionDecrypt_url ($url,$key)  {      returnDecryptBase64_decode(Rawurldecode($url)),$key); }  functionGeturl$str,$key)  {      $str= Decrypt_url ($str,$key); $url _array=Explode(' & ',$str); if(Is_array($url _array))      {          foreach($url _array  as $var)          {              $var _array=Explode(' = ',$var); $vars[$var _array[0]] =$var _array[1]; }      }      return $vars; }

Test

$key= ' key ';//production encryption parameter address for($i= 0;$i<10;$i++){    Echo"<a href=./url.php?url=". Encrypt_url ("id=$i&act=123456&time= ". Time(),$key)." >php Technical Articles$i</a><br> ";}//Get parameter Address$get= Geturl ($_get[' URL '],$key);Var_dump($get);

URL address transfer encryption and decryption function in PHP development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.