search
Homephp教程PHP源码对URL加密和解密的一个函数

如果你的页面访问入口是这种类型:xxxx.php?cGFnZWlkPTEmtLS9qMjLPWFkbWluJmFjdGlvbj1pbml0X2RlZmF1bHQ=那么需要进行_GET变更的解析,下面是两个函数,一种是判断是否是BASE64加密函数,一种是对其进行解析的函数

xxxx.php?cGFnZWlkPTEmtLS9qMjLPWFkbWluJmFjdGlvbj1pbml0X2RlZmF1bHQ=这咱例子的生成是使用这样的写法:
xxxx.php?".base64_encode("ID=33&action=init")."
使用本函数,会得到ID和action的值

PHP代码

//判断GET变量是否为BASE64编码,不是很科学,需要进一步改进此函数
function isBase64()        {
    global $_SERVER;
    $QUERY_STRING = $_SERVER['QUERY_STRING'];
    $Code = base64_decode($QUERY_STRING);//print base64_decode($Code);
    $Array = explode('=',$Code);
    if(sizeof($Array)>1)        {
        return 1;
    }
    else
        return 0;
}
 
//重置_GET变量
function CheckBase64()    {
    global $_GET,$_SERVER;
    $QUERY_STRING = $_SERVER['QUERY_STRING'];
    $QUERY_STRING_ARRAY = explode('&',$QUERY_STRING);
    $QUERY_STRING = $QUERY_STRING_ARRAY[0];
    $QUERY_STRING = base64_decode($QUERY_STRING);
    $Array = explode('&',$QUERY_STRING);
    $_GET = array();
    //形成新的_GET变量信息
    $NewArray = array();
    for($i=0;$i<sizeof($Array);$i++)        {
        if($Array[$i]!="")        {
            $ElementArray = explode(&#39;=&#39;,$Array[$i]);
            $_GET[(String)$ElementArray[0]] = $ElementArray[1];
            $NewArray[$i] = $ElementArray[0]."=".$ElementArray[1];
        }
    }
    //附加GET变量形成部分
    for($i=1;$i<sizeof($QUERY_STRING_ARRAY);$i++)        {
        if($QUERY_STRING_ARRAY[$i]!="")        {
            $ElementArray = explode(&#39;=&#39;,$QUERY_STRING_ARRAY[$i]);
            $_GET[(String)$ElementArray[0]] = $ElementArray[1];
            $NewArray[$i] = $ElementArray[0]."=".$ElementArray[1];
        }
    }
    //形成新的_SERVER变量信息
    $_SERVER[&#39;QUERY_STRING&#39;] = join(&#39;&&#39;,$NewArray);
    $_SERVER[&#39;REQUEST_URI&#39;] = $_SERVER[&#39;PHP_SELF&#39;]."?".$_SERVER[&#39;QUERY_STRING&#39;];
}
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor