I have a URL of the form:- http://www.sboxeppp.com:88/phones.php?iden=true#6786
Now i want to retrieve number (6786) followed by # in server side. How can i do that?
I have a URL of the form:- http://www.sboxeppp.com:88/phones.php?iden=true#6786
Now i want to retrieve number (6786) followed by # in server side. How can i do that?
anything behind the hash can only be accessed by client side scripts, since it won't be sent to the server you can use the parse_url() function
You cannot do that. The part of the url after the hash is called a fragment, and it does not get sent to the server. It's only available to client scripting.
The only way that you could do this is by retrieving the fragment from JavaScript (using window.location.hash
) and communicating this information to the server with an AJAX request specifically made for this purpose. Of course this means that the server will have to render the page first and get notified of the fragment later, which is a totally different workflow than what you want.
You can't do that, because it's a directive for browser only. You can use AJAX requests to send the required info to server.
Use parse_url
:
parse_url('http://www.sboxeppp.com:88/phones.php?iden=true#6786',
PHP_URL_FRAGMENT);
Notice that the fragment doesn't get sent to the server if it's in the form's target
property. Instead, just write the information in the fragment in a hidden element, like this:
<input type="hidden" name="_fragment" value="6786" />
And read the fragment from $_POST['_fragment']
.
If the fragment is generated client-side (or somehow determined by the user), you'll have to create that element on the client. You can access the current fragment in JavaScript with window.location.hash
.
Right, it didnt let me post that as an answer -
var hashNumber = window.location.hash
should work.
hashNumber = hashNumber.substring(1)
See: