簡體   English   中英

如何從PHP的哈希鏈接獲取參數?

[英]How do I get parameter from hash links in PHP ?

這是我的鏈接: http://projects/timp#?period=2014-6-25
顯然這段代碼:

$period = $_GET['period']; echo $period;

不起作用。 我能做什么 ?

更改網址的格式,以免中間沒有# # ...之后有一個?name = value似乎很奇怪。

您無法直接獲取哈希,因為它不會到達服務器,您可能可以采取解決方法。 嘗試這樣的事情:

(不要忘記在網址上#?period=2014-6-25值) #?period=2014-6-25

<?php

if(isset($_POST['submit'])) {
    $hash = $_POST['hash'];
    $hash = str_replace(array('#', '?'), '', $hash);
    parse_str($hash, $url);
    $period = $url['period'];
    echo $period; // 2014-6-25
}

?>

<form method="POST">
    <input type="hidden" name="hash" value="" />
    <input type="submit" name="submit" />
</form>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function(){

    var hash = window.location.hash;
    $('input[name="hash"]').attr('value', hash);

});
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM