views:

58

answers:

2

Possible Duplicate:
retrieve the hash in the url with php?

iam having a page that is containg bookmark in its url like

http://www.abc.com/page_url#bookmark

iam using $_SERVER['HTTP_HOST'] and $_SERVER["REQUEST_URI"] to get the url but its gigvng URL only upto http://www.abc.com/page_url i.e. its not giving my bookmarked link in it.

How can i fetch my complete url(with '#' content) in php????

Edit:

see what i want to do is i want to add '/' in my URL i.e. if a URL is http://www.abc.com/page_url#bookmark then i want to redirect it to http://www.abc.com/page_url#bookmark/ .when im doing this with $_SERVER["REQUEST_URI"] its resulting into http://www.abc.com/page_url/#bookmark which is wrong. Now plz tell how can i do this???

+6  A: 

Most browsers don't send the #fragment when requesting a URL, but handle it internally... so PHP has no access to that information

Mark Baker
isn't there any other way to fetch it???
developer
@developer, no there isn't as it is **not** sent to the server.
Darin Dimitrov
PHP can only work with the request sent to the server by the browser. You could pass the target slightly differently: http://www.abc.com/page_url?fragment=bookmark#bookmark and access it then using $_GET['fragment']
Mark Baker
It will be available on client side in JavaScript but not at the time PHP renders the page.
Pekka
plz see my edit
developer
+3  A: 

The browser doesn't send the webserver that information (called the "fragment") when requesting a web page. In fact, it may even not make a request at all (if you click on an link to the same page, but a different fragment).

The only way to do this is with Javascript. You can fetch the fragment with self.document.location.hash. Then you can make a separate request (e.g. ajax) to send the server that information.

This would be useful e.g. to store statistics on which sections users have landed when they followed a link, but you can change how the page rendered server-side based on the fragment (you could of course, with javascript, redirect the user to another page, or to the same page passing the fragment in the query string so that it could then be rendered differently).

Artefacto