user3184286
user3184286

Reputation: 97

How to get url value after #

I am using PHP for my website. i want to fetch URL value that is like test/show.php?ID=247#about.

when i used session variable

<?php

 session_start();
 $url = $_SERVER['REQUEST_URI'];

echo $url;

?>

its printing only test/show.php?ID=247.

i am not getting #about. this #about i want to used to redirect my main page menu.

Please can any one tell me how to get it.

thank you.

Upvotes: 0

Views: 297

Answers (2)

user2864740
user2864740

Reputation: 61885

You cannot - without custom client-side support1

The "hash" (or Fragment Identifier) is not sent to the server normally.

The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the web server .. When an agent (such as a Web browser) requests a web resource from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the document type and fragment value.


1 You could, for instance, use JavaScript hook into the form submit event, read from window.location.hash as appropriate, and shove the value into a control for the form submission .. however, the general design should be rethought (or rather, avoided) for several reasons:

  1. Hash changes are generally used for client-side state management and "AJAX" navigation.
  2. Increased complexity, and unexpected/browser-subversive behavior.
  3. It won't work on "normal" links or on the first page load after navigation.

Upvotes: 2

Pavel
Pavel

Reputation: 4217

You can not access tis part (hash) in PHP, you can access it using JavaScript

<script type="text/javascript">
    alert(document.location.hash)
</script>

Upvotes: 1

Related Questions