php实现URL加密解密的方法

时间:2021-05-02

本文实例讲述了php实现URL加密解密的方法。分享给大家供大家参考,具体如下:

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN"> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312" /> <meta http-equiv="content-language" content="zh-CN" /> <meta http-equiv="pragma" content="no-cache" /> <meta http-equiv="expires" content="0" /> <meta http-equiv="MSThemeCompatible" content="Yes" /> <meta http-equiv="imagetoolbar" content="no" /> <meta http-equiv="widow-target" content="_top" /> <meta name="robots" content="index, follow" /> <meta name="author" content="3945, [email]ljm77@km169.net[/email]" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta name="copyright" content="Copyright 3945 All Rights Reserved" /> <title>无标题文档</title> <style type="text/css"> <!-- a, a:link{text-decoration: none; color:#000000; font-size:9pt;} a:visited{text-decoration: none; color:#000000;} a:hover{text-decoration: underline; color:red;} body, td, p, li, div, select{font-size:9pt; font-family:"宋体";} --> </style> </head> <body> <?php function query_encode($sQuery) {//加密链接 if(strlen($sQuery)==0) { return ''; } else { $s_tem = preg_replace("/&/i", '&', $sQuery); $s_tem = preg_replace("/&/i", '&', $s_tem); $a_tem = explode('&', $s_tem); shuffle($a_tem); $s_tem = implode('&', $a_tem); $s_tem = rawurlencode($s_tem); $s_tem = base64_encode($s_tem); $s_tem = strrev($s_tem); return $s_tem; } } function query_decode($sEncode) {//解密链接 if(strlen($sEncode)==0) { return ''; } else { $s_tem = strrev($sEncode); $s_tem = base64_decode($s_tem); $s_tem = rawurldecode($s_tem); return $s_tem; } } function rebuild_GET() {//重写$_GET全局变量 $_GET = array(); $s_query = $_SERVER['QUERY_STRING']; if(strlen($s_query)==0) { return; } else { $s_tem = query_decode($s_query); $a_tem = explode('&', $s_tem); foreach($a_tem as $val) { $tem = explode('=', $val); $_GET[$tem[0]] = $tem[1]; } } } rebuild_GET(); echo 'GET:<pre>'.print_r($_GET, true).'</pre>'; function testGET() { echo 'Function GET:<pre>'.print_r($_GET, true).'</pre>'; } testGET(); ?> <br /><br /><br /> <? for($i=1; $i<10; $i++) { $s_url = query_encode('ac=index:logo& style="color: #007700">.$i); echo sprintf('<a href="?%s">TEST: %s</a><br />', $s_url, $s_url); } ?> </body> </html>

希望本文所述对大家PHP程序设计有所帮助。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章