Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP & Hash / Fragment Portion of URL

I am trying to find a way to save the hash portion of a url and as a PHP variable. This idea is a bit kooky, but bear with me...

I'd like to extract the "location" fragment from the following URL and save it as a PHP variable.

http://www.example.com/#location

However, discussion at this link indicates that the fragment of a URL is only reachable through JavaScript.

But would it be possible to create a link where the fragment is duplicated in the URL, parsed by PHP, and then removed by mod rewrite? So....

Original url:

http://www.example.com/location/#location

PHP gets location variable thanks to the plain "location" in the URL

Apache then rewrites the link to:

http://www.example.com/#location

I'm curious to know if there is an elegant way to solve this problem.

like image 235
mikey_w Avatar asked Jul 21 '09 22:07

mikey_w


1 Answers

You'll need to use Javascript to read this. There are a few different options - upon page load, you could use an XmlHTTPRequest (AJAX request) to tell the server what the additional URL parameters were. Alternatley you could check to see if there are additional parameters (also via Javascript), and if you find any, post back to a different URL that has these parameters encoded into the URL itself.

like image 167
pix0r Avatar answered Oct 13 '22 12:10

pix0r