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