2013-06-21 90 views
1
http://xxxx.us/a/6126/securitycheckzpsfc10cc9.jpg#id=558554 

我想獲取哈希後的Url參數。獲取URL參數在php之後#從地址欄Url

$hash = $_GET['hash']; 

不工作

我想獲取地址從地址欄。 並獲取散列後的部分。

<?php 
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 
$url1 = parse_url($url); 
echo $url1['fragment']; 
?> 

這也不起作用。

+0

我不知道爲什麼你會認爲,要麼你嘗試將實際工作。 –

+2

哈希後的參數不發送到服務器,它的瀏覽器錨點 – DevZer0

+1

閱讀此:http://stackoverflow.com/questions/2317508/php-get-value-from-url-after-sign – stackErr

回答

0

散列不傳遞給服務器,它僅在客戶端。

但是,您試圖做的事情是不可能的,但是,通過Javascript可以獲得完整的URL。

你應該看看更好的方式來做你想做的事情。爲什麼不將它作爲GET值傳遞?

1

使用JavaScript location.hash,你可以哈希更改爲GET參數,並將其發送給你的PHP腳本

<!DOCTYPE HTML> 
<html> 
<head> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> 
</head> 
<body> 
<a href="http://example.com/?some_parameter=x" class="hashed_link">Link</a> 

<script> 
    $().ready(function(){ 
     // navigate to in page anchor for testing 
     window.location.href="#hash=12345678"; 

     // bind anchor click event 
     $('.hashed_link').click(function(e){ 
      e.preventDefault(); 
      hash_anchor = $(this).attr('href')+'&'+location.hash.substr(1); 

      alert(hash_anchor); 
      //window.location.href=$(this).attr('href')+location.hash; 
     }); 
    }); 
</script> 
</body> 
</html> 
+0

但是您必須刷新頁。 –

+0

我沒有看到有關不刷新頁面的任何信息... – user20232359723568423357842364

+0

你沒有用你的用戶名得到'index out of bounds exception'嗎? :P – anubhava