php對url加密解密,PHP文件解密

本文目錄一覽:

php通過base64實現動態url加密和解密的過程

BASE64不算加密,不要學微軟,沒有實際價值、浪費系統資源。

在客戶端是無法使用PHP的,PHP只能在服務器上運行,在客戶端可以考慮使用JAVASCRIPT進行BASE64編碼,網上有許多這樣的例子,比如:

在服務器端可以使用PHP識別BASE64編碼,使用函數base64decode即可。

分享一個php加密方法,這個方法還比較實用

我們在開發過程中,有的時候GET傳值,字符串太長,我們可以用這個方法,在傳值之前先調用函數lock_url(加密字符串),加密以後在傳遞,GET接受以後用函數unlock_url(待解密字符串)進行解密。

如果大家有更好更簡單的方法,發評論區我們一起討論學習!

function lock_url($txt)

{

$key = ‘]!L]_w{O}zEIs!.f(T[|ZGQaxS”:?#`v%EburotLZi”KdKs@QivlJ[PjWw`.wcT’; //key

$chars = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+”;

$nh = rand(0,64);

$ch = $chars[$nh];

$mdKey = md5($key.$ch);

$mdKey = substr($mdKey,$nh%8, $nh%8+7);

$txt = base64_encode($txt);

$tmp = ”;

$i=0;$j=0;$k = 0;

for ($i=0; $istrlen($txt); p=”” {

$k = $k == strlen($mdKey) ? 0 : $k;

$j = ($nh+strpos($chars,$txt[$i])+ord($mdKey[$k++]))%64;

$tmp .= $chars[$j];

}

return urlencode($ch.$tmp);

}

//解密函數

function unlock_url($txt)

{

$key = ‘]!L]_w{O}zEIs!.f(T[|ZGQaxS”:?#`v%EburotLZi”KdKs@QivlJ[PjWw`.wcT’;//key

$txt = urldecode($txt);

$chars = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-=+”;

$ch = $txt[0];

$nh = strpos($chars,$ch);

$mdKey = md5($key.$ch);

$mdKey = substr($mdKey,$nh%8, $nh%8+7);

$txt = substr($txt,1);

$tmp = ”;

$i=0;$j=0; $k = 0;

for ($i=0; $istrlen($txt); p=”” {

$k = $k == strlen($mdKey) ? 0 : $k;

$j = strpos($chars,$txt[$i])-$nh – ord($mdKey[$k++]);

while ($j0) $j+=64;

$tmp .= $chars[$j];

}

return base64_decode($tmp);

}

針對url的加密與解密

encodeURIComponent(string)加密,decodeURIComponent(string)解密

city: encodeURIComponent(`’${this.cityVal}’`)//this.cityVal為要加密的中文

let href = util.getUrlParam(‘city’)

console.log(‘解析url地址1=====’,href)

console.log(‘解析url地址2=====’,decodeURIComponent(href))

console.log(‘解析url地址2=====’,decodeURIComponent(decodeURIComponent(href)))//需解析兩層

原創文章,作者:GERY,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/139637.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
GERY的頭像GERY
上一篇 2024-10-04 00:22
下一篇 2024-10-04 00:22

相關推薦

發表回復

登錄後才能評論