Skip to content Skip to sidebar Skip to footer

What's The Best Way To Access A Uri Variable After A Hashtag From Php?

I have Javascript updating my URI as below: /index.php?page=list#page=news But I would like to make page=news accessible somehow from my server so that when the URI is copied and

Solution 1:

You can't. That data, called the fragment, is reserved for client side processing and thus is never sent to the server.

The only way to utilize the fragment is to have Javascript intervene at some point. This probably means checking for a hash-tag on the page onload, and then displaying the proper data.

You could make your entire page loaded via Javascript. While it would kill compatability for anyone who turned off Javascript, it would ensure that the hash tag eventually gets sent to PHP

Basically, it would look something like this:

  • PHP Sends Page
  • Javascript reads the hastag
  • Make a URL with a hashtag parameter (loader.php?page=list&page=news) (Note that in the above, page=list wil be overriden by page=news, so $_GET['page'] will be news.
  • AJAX call to PHP
  • Load the content into a div.

(And this question is very much a duplicate question)

Post a Comment for "What's The Best Way To Access A Uri Variable After A Hashtag From Php?"