获取当前URL未获取ID,基于类的筛选器


Fetch Current URL not getting ID , class based filters

我正在尝试获取当前页面的URL,用于if-else语句。

我的URL如下:http://something.com/fetch_url.php#filter=.apples

我的代码是:

<?php
echo $_SERVER['REQUEST_URI'].'<br/>';
?>

它给了我:

/仅限fetch_url.php,但在if-else的情况下,我需要检查#filter=.apples。请引导。

尝试使用正确的URLhttp://something.com/fetch_url.php?filter=apples

#URL中的部分永远不会接近web服务器,因此您无法访问它。

并像这样使用if语句。

if($_REQUEST['filter']=='apples'){
   //then perform your action here according to requirements
}else{
   // otherwise provide instruction for the else condition here
}

URL中的#部分永远无法到达web服务器,因此您无法访问它。我们一直在使用的一种解决方法是使用Javascript通过window.location.hash访问它,然后在必要时单独发布到服务器以获取此哈希。

以前也有人问过类似的问题:从php中的URL获取片段(hash';#';后的值)