How to Get the Value After the Hash in "Somepage.Php#Name"

How to get the value after the hash in somepage.php#name?

I don't think it's possible. The string after # is interpreted by the browser as an anchor name within the current page. It is not passed to the server.

Get fragment (value after hash '#') from a URL

If you want to get the value after the hash mark or anchor as shown in a user's browser: This isn't possible with "standard" HTTP as this value is never sent to the server (hence it won't be available in $_SERVER["REQUEST_URI"] or similar predefined variables). You would need some sort of JavaScript magic on the client side, e.g. to include this value as a POST parameter.

If it's only about parsing a known URL from whatever source, the answer by mck89 is perfectly fine though.

How can i get the page.html#PARAMETERS through PHP?

You can't, at least not directly. The fragment identifier is never sent to the server.

You could extract it in JS using location.hash and then trigger another HTTP request to the server that includes it as data (e.g. in the query string).

Getting FULL URL with #tag

The browser doesn't actually send anything that comes after the hash(#) to the server because it is resolved within the browser.

PHP get anchor attribute

There is no way to get things after "#" in php, because this data is not provided to server, only url without data after "#", but if you are executing php script through JavaScript, you can Always split url into "#" and send the data as parameter or value of some hidden field.

PHP isset($_GET) not triggered

The browser is never sending hash to the server, when requesting data.

You have to send it manually, ie. using jquery:

var hash = window.location.hash;
$.ajax({ url: 'content.php?photo=' + hash});

Filepath and it's URL variable is cut short when concatenated

Certain characters need to be encoded when used in URLs...a space is one of them. JavaScript provides a global function to encode any necessary characters for URLs - encodeURIComponent. Instead of just concatenating $input, you would concatenate:

encodeURIComponent($input)

Reference:

  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent


Related Topics



Leave a reply



Submit