Forum Moderators: coopster
I'm trying to capture a full URL including an ID, for eg: http://example.com/index.php#id
How do I get the pound info? I'm a fairly seasoned PHP coder but a simple solution to this escapes me. There must be an easy solution for this I'm missing or forgetting.
Thanks :)
[edited by: dreamcatcher at 7:48 am (utc) on Feb. 18, 2009]
[edit reason] use example.com. Thanks. [/edit]
if you click on a link containing a fragment identifier and the url is for the current document, the server never sees a request for a new resource.
If all you need is logging, you can have javascript ping a php script whenever the fragment changes. But if you're trying to have PHP produce different output based on the fragment, you're out of luck.
So a function like the parse_url function can retrieve the fragment part for the web app to get the visitor to the exact position within the page. This case will be handled by the server end instead of the browser. I believe it's one of the reasons for functions like the parse_url to return the fragment part in PHP.
<?php
echo '<pre>'; print_r($_SERVER); echo '</pre>';
?>
And then visit that page and test different fragments. You'll see that the fragment simply isn't part of the data that the server knows about.
The only way to get the current page's fragment to PHP is to have a separate Javascript request sent to the server. But, by that point, PHP has already outputted whatever it's going to output for the original page.
So a function like the parse_url function can retrieve the fragment part for the web app to get the visitor to the exact position within the page. This case will be handled by the server end instead of the browser. I believe it's one of the reasons for functions like the parse_url to return the fragment part in PHP.
The parse_url() [uk.php.net] is not just for parsing URLs that have been grabbed from the page request (which, as mentioned, does not contain a fragment identifier), but the (string)URL might have been pulled from a DB or created by some other means where there might actually be a fragment identifier, this can then be passed to the client/browser in the response.