PHP 小工具合集

发布于 2020-07-02  133 次阅读


1.UUID生成器(伪)

function UUID():string
{
    $chars = md5(uniqid(mt_rand(), true));
    $uuid  = substr($chars,0,8) . '-';
    $uuid .= substr($chars,8,4) . '-';
    $uuid .= substr($chars,12,4) . '-';
    $uuid .= substr($chars,16,4) . '-';
    $uuid .= substr($chars,20,12);
    return $uuid;
}

2. 获取的完整url

 function getFullUrl(){
     # 解决通用问题
     $requestUri = '';
     if (isset($_SERVER['REQUEST_URI'])) {
        $requestUri = $_SERVER['REQUEST_URI'];
     } else {
         if (isset($_SERVER['argv'])) {
              $requestUri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['argv'][0];
         } else if(isset($_SERVER['QUERY_STRING'])) {
         }
     }
 //    echo $requestUri.'<br />';
     $scheme = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
     $protocol = strstr(strtolower($_SERVER["SERVER_PROTOCOL"]), "/",true) . $scheme;       //端口还是蛮重要的,毕竟需要兼容特殊的场景
     $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
     # 获取的完整url
     $_fullUrl = $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $requestUri;
     return $_fullUrl;
 }

 


忍耐无法忍耐的事物,才是真正的忍耐。