Reputation: 318
I want to get the URL using (preferably) PHP or JavaScript. The page was opened using an anchor name (e.g. index.php#aboutme
). When I use
$host = $_SERVER['HTTP_HOST'];
$script = $_SERVER['SCRIPT_NAME'];
$params = $_SERVER['QUERY_STRING'];
it returns http://afterimagedesign.tk/index.php
without the #home
on the end. How can I get this?
Upvotes: 1
Views: 135
Reputation: 385
The only way to access this data with PHP would be to send it to PHP via an AJAX call when the page loads. As the other responses have said, the hashtag is never sent to PHP inside the original request. So you would have to send it afterwards.
If this is information you need, you would have to change your application to not use hashtags and instead append this data to the query string (ie index.php?home rather then index.php#home and manually scroll the page using javascript when it loads based on this.
Upvotes: 0
Reputation: 174977
PHP cannot ever get this hashtag (that's what it's called), because the browser never sends it to the server in any form.
JavaScript can access it with window.location.hash
, but that's client-side.
What are the difference between server-side and client-side programming?
Upvotes: 2
Reputation: 3659
<?
echo parse_url("http://localhost/index.php#aboutme",PHP_URL_FRAGMENT);
?>
Output: aboutme
or with JS
window.location.hash
Upvotes: 0