0

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 ?

Attila Naghi
  • 2,535
  • 6
  • 37
  • 59
  • 2
    possible duplicate of [Can PHP read the hash portion of the URL?](http://stackoverflow.com/questions/940905/can-php-read-the-hash-portion-of-the-url) – raina77ow Jun 27 '14 at 11:51
  • As "timp#" is not a valid server side file.. you can't get all the data which coming by GET. If it's mandatory that your URL will be like this "time#" then write a .htaccess file for forcing all the control which are coming to "time#" to a specific page like.. time.php. Then on that page you can use $_GET to catch all those GET values. – Suresh Jun 27 '14 at 11:55
  • @mi6crazyheart, no, the server won't see the `#`, and if you do a redirect, you'll just loose the fragment (the `#` and what follows it). – jcaron Jun 27 '14 at 11:56
  • is it possible to get the full url with # , in a php variable ? – Attila Naghi Jun 27 '14 at 12:10
  • onload, get the hash, append it on a hidden value, then process the form in php – user1978142 Jun 27 '14 at 12:40

2 Answers2

0

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 #...

jcaron
  • 17,302
  • 6
  • 32
  • 46
0

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>
user1978142
  • 7,946
  • 3
  • 17
  • 20