如何将url绑定到php中的变量


how to bind url to variable in php

我想将完整的URL绑定到PHP变量中。

我的URL如下:http://develop.example.com/spf#users/admin

要获得URL,我使用以下内容:

http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]

对于哈希值,使用这个JS:

document.write(window.location.hash);

所以我的PHP变量如下所示:

$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"."<script>document.write(window.location.hash);</script>";

当我回显$current_url时,我得到的输出是:http://develop.example.com/spf#users/admin

现在我想检查一下当前的URL:

if ($current_url != "http://develop.example.com/spf#users/admin") {
    echo "you are NOT the admin";
}
else {
    echo "you are the admin";
}

不幸的是,即使URL完全相同,他仍然坚持说:"你不是管理员"。

这里出了什么问题?

您可以使用以下脚本,并且您的代码是正确的,但问题是"document.write(window.location.hash);"此代码删除它,然后运行

   <?php
    $current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

    $match="http://localhost:900/at/";
    // echo base64_encode($current_url);
    // echo "<br>";
    // echo base64_encode($match) ;

    if ($current_url==$match) {
        echo "you are the admin";
    }
    else {
     echo "you are NOT the admin";
    }

    ?>