2016-04-03 74 views
0

我想獲取我當前的頁面URL,爲if-else語句。取得當前的URL沒有得到ID,基於類的過濾器

我的網址是這樣的:http://something.com/fetch_url.php#filter=.apples

而且我的代碼是:

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

它給我:僅

/fetch_url.php,但我需要檢查#過濾器= .apples,在if-else的情況下。 請指導。

+1

url的哈希部分永遠不會發送到Web服務器。 – Federkun

+1

嘗試使用像「http://something.com/fetch_url.php?filter = apples'這樣的正確網址 – RiggsFolly

回答

0

A #部分URL無法到達Web服務器,因此您無法訪問它。我們使用的一種解決方法是使用Javascript通過window.location.hash訪問它,然後在服務器上單獨發佈帖子以獲取該散列(如果有必要)。使用Get fragment (value after hash '#') from a URL in php

1

嘗試像http://something.com/fetch_url.php?filter=apples

#部分正確的URL在URL從未接近到Web服務器,因此你不能訪問它:之前

類似的問題已經被問。

並使用if語句這樣。

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