简体   繁体   中英

How do I get parameter from hash links in PHP ?

This is my link: http://projects/timp#?period=2014-6-25
Obviously this code :

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

does not work . What can i do ?

Change the format of the URLs so that you don't have the # in the middle. It does seem quite weird to have a ?name=value after the # ...

You can't directly get the hash since it won't reach to the server, you can probably do a workaround. Try something like this:

(Don't forget to append the hash on the 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM