Assuming a URL of:
www.example.com/?val=1#part2
PHP can read the request variables val1
using the GET array.
Is the ha
It is retrievable from Javascript - as window.location.hash
. From there you could send it to the server with Ajax for example, or encode it and put it into URLs which can then be passed through to the server-side.
The main problem is that the browser won't even send a request with a fragment part. The fragment part is resolved right there in the browser. So it's reachable through JavaScript.
Anyway, you could parse a URL into bits, including the fragment part, using parse_url(), but it's obviously not your case.
<?php
$url=parse_url("http://domain.com/site/gallery/1?user=12#photo45 ");
echo $url["fragment"]; //This variable contains the fragment
?>
This is should work
I think the hash-value is only used client-side, so you can't get it with php.
you could redirect it with javascript to php though.
Th part of an URI after the #
is called "fragment" and is by definition only available/processed on client side (see https://en.wikipedia.org/wiki/Fragment_identifier).
On the client side, this can be accessed using javaScript with window.location.hash
.
Another solution is to add a hidden input field to the php page:
<input type="hidden" id="myHiddenLocationHash" name="myHiddenLocationHash" value="">
Using javascript/jQuery you can set the value of this field on the page load or responding to an event :
$('#myHiddenLocationHash').val(document.location.hash.replace('#',''));
In php on the server side you can read this value using the $_POST collection:
$server_location_hash = $_POST['myHiddenLocationHash'];