When a PHP site is requested like e.g. somesite.php?a=some text # some more
Currently it seems like $_REQUEST["a"] returns the string "some text ", how can I get "some text # some more". Are there other characters which get similar treatment by PHP?
When a PHP site is requested like e.g. somesite.php?a=some text # some more
Currently it seems like $_REQUEST["a"] returns the string "some text ", how can I get "some text # some more". Are there other characters which get similar treatment by PHP?
The "#" character is special in the URL specification; it refers to a location on the page (named by an 'a' tag like: <a name='top'>this is the top of the page</a>). It, and everything after it, is not passed to the server (php).
You can't. The browser doesn't send the part of the url after the # to the server.
So, it's not PHP that removes that part of the URL, it never sees it.
The hash (#) is a "Fragment identifier" (also informally known as an "anchor") and refers to a location within the page - and you're right, it doesn't get sent to the server.
It's the only URL character that behaves like this.
If you need to include a hash character in a URL, you need to encode it as %23
somesite.php?a=<?=urlencode( "some text # some more" )?>
Turns it into:
somesite.php?a=some+text+%23+some+more
The # character, and any characters that follow it, specify and anchor. This is a point within the page that the browser will scroll to.
As far as I know, this is for the browser's use only, and is never transmitted to the server side - presumably because it means nothing to the server,
You can use urlencode() & urldecode() functions it will be %23 instead of # symbol
If you have to have it, you can write javascript to re-post it for you:
<script>
function checkHash(){
var hash = window.location.hash;
if(hash){
// see if we've already included this
var loc = window.location.pathname;
if(!loc.indexOf('hashData=') >= 0){
// hashData param not included
window.location.href = loc + '&hashData=' + encodeURIComponent(hash) + hash;
}
}
};
checkHash();
</script>
There are some obvious issues with this (like it double-submits items). Note - if someone clicks on a hash link in the page, the code won't re-run, so you would need to monitor the hash for changes. You may or may not care about that case.