我如何获得参数从哈希链接在PHP


How do I get parameter from hash links in PHP ?

这是我的链接:http://projects/timp#?period=2014-6-25
显然这段代码:

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

不起作用。

更改url的格式,这样您就不会在中间有#。在#

之后有一个?name=value似乎很奇怪。

您不能直接获得哈希,因为它不会到达服务器,您可能可以做一个解决方案。试试这样做:

(不要忘记在url上添加哈希值)#?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>