php实现URL加密解密的方法

荣誉就像河流:轻浮的和空虚的荣誉浮在河面上,沉重的和厚实的荣誉沉在河底里。雨会停,心会晴,没有什么会永远糟糕透顶。

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

<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 rel="nofollow noopener noreferrer" href="?%s">TEST: %s</a><br />', $s_url, $s_url);
}
?>
</body>
</html>

PS:关于加密解密感兴趣的朋友还可以参考本站在线工具:

URL网址16进制加密工具:
http://tools.haodaima.com/password/urlencodepwd

密码安全性在线检测:
http://tools.haodaima.com/password/my_password_safe

高强度密码生成器:
http://tools.haodaima.com/password/CreateStrongPassword

MD5在线加密工具:
http://tools.haodaima.com/password/CreateMD5Password

迅雷、快车、旋风URL加密/解密工具:
http://tools.haodaima.com/password/urlrethunder

在线散列/哈希算法加密工具:
http://tools.haodaima.com/password/hash_encrypt

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

本文php实现URL加密解密的方法到此结束。好好去爱,去生活。青春如此短暂,不要叹老。偶尔能够停下来休息,可是别蹲下来张望。走了一条路的时候,记得别回头看。时不时问问自我,自我在干嘛?记住,每一天的太阳都是新的,不要辜负了完美的晨光。小编再次感谢大家对我们的支持!

您可能有感兴趣的文章
Laravel的加密解密与哈希实例讲解

六种php加密解密方法实例讲解

php实现的rc4加密解密类定义与用法示例

PHP实现的DES加密解密类定义与用法示例

PHP实现基于3DES算法加密解密字符串示例