0

Possible Duplicate:
Can PHP read the hash portion of the URL?

I've a gallery site.
The actual selected album is marked in the URL with a hashtag.
Example with the album HDR:

http://www.example.com/gallery#HDR

Now i want to split the URL with parse_url. But there i need the URL in a String, WITH the hashtag. So it doesn't work with $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']...

The only way i know to reach the URL is with JavaScript.
But how can i convert a JavaScript variable in a PHP variable?

Community
  • 1
  • 1
Michael Schmidt
  • 9,090
  • 13
  • 56
  • 80
  • 1
    The portion after the `#` is not sent to the server at all. There's no way to retrieve it. You'll have to rewrite your URL's to include the necessary portion as a query string (e.g. map `/gallery#HDR` into `/gallery?foo=HDR`, and use `$_GET['foo']` instead). – Matt Jan 14 '13 at 13:24
  • 1
    That is a fragment identifier, not a hashtag. A hashtag is a highlighted search term on a social network. – Quentin Jan 14 '13 at 13:24
  • 2
    You may want to read this: http://stackoverflow.com/questions/940905/can-php-read-the-hash-portion-of-the-url – Alvin Wong Jan 14 '13 at 13:24
  • @AlvinWong: There i get the parse_url method. But there is nowhere a solution for the php-string... – Michael Schmidt Jan 14 '13 at 13:25
  • Don't use [fragment identifiers to link to things that aren't actual fragments](http://isolani.co.uk/blog/javascript/BreakingTheWebWithHashBangs) of a document. Use [pushState and friends](http://stackoverflow.com/questions/5216314/how-is-github-changing-pages-and-the-url-so-smoothly-without-ajax) instead. – Quentin Jan 14 '13 at 13:25
  • If you want to send data from JS to PHP, have a look at [Ajax](http://en.wikipedia.org/wiki/Ajax_%28programming%29). You will find tons questions on SO regarding this topic. – Felix Kling Jan 14 '13 at 13:26
  • @Matt: A good looking URL is important to me... Is this the only way? – Michael Schmidt Jan 14 '13 at 13:27
  • 2
    @dTDesign — No, you can just take the `#` out and process the whole URL server side. Using a `#` is a hack to provide some of the features of [pushState and friends](http://stackoverflow.com/questions/5216314/how-is-github-changing-pages-and-the-url-so-smoothly-without-ajax) in old browsers. You don't need to go near it for pretty URLs. – Quentin Jan 14 '13 at 13:29
  • @Quentin: Thank you! But can't mark your comment as my accept solution :) – Michael Schmidt Jan 14 '13 at 15:01

1 Answers1

0

You cannot convert a javascript variable to php, because php is server sided and js client sided.

No variable in $_SERVER contains the "#xxx" part.

Check: Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?

Community
  • 1
  • 1
jussi
  • 2,166
  • 1
  • 22
  • 37