![](/img/trans.png)
[英]Php, I want to add a parameter for redirections in ALL links, how to do that?
[英]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.