0

abcd.com/indexreadmore.php?#cat2

This is what the url in which I want to get all the parts like above mentioned, I can get a bit but not able to get the #cat2 and help me fetch entire url in php from the url bar.

Rikesh
  • 24,843
  • 14
  • 73
  • 84
user2983060
  • 19
  • 1
  • 1
  • 9
  • For the sake of brevity, it's called a [*"fragment" identifier*](http://en.wikipedia.org/wiki/Fragment_identifier) – Emissary Feb 21 '14 at 08:40

3 Answers3

0

You cannot get the URL after the # in PHP..

The maximum you can attain is abcd.com/indexreadmore.php , To verify this you could just do a print_r($_SERVER); on your PHP code.

The content after the # can be retrieved only through JavaScript.

Shankar Damodaran
  • 65,155
  • 42
  • 87
  • 120
0

If you mean to parse the url, then there is parse_url function.

var_dump(parse_url('abcd.com/indexreadmore.php?#cat2'));

The browser does not send the hash fragment to the server if you mean get it in indexreadmore.php.

xdazz
  • 149,740
  • 33
  • 229
  • 258
0

The hashtags are not sent to the server, only the browser so PHP wouldn't be able to parse that from the address. You'd have to use javascript:

<script type="text/javascript">alert(window.location.hash);</script>
Curtis W
  • 513
  • 4
  • 10
  • I can get the url after # but getting trouble during the comparison of urls like the same.so help me how to compare the urls like mentioned above. Thank you. – user2983060 Feb 21 '14 at 08:35
  • I don't understand what you're trying to do, what do you mean by compare, what are you trying to compare with? Did you want the full URL using javascript? If so try: alert(window.location.href); – Curtis W Feb 21 '14 at 08:44
  • Thanks for your help.I have stored a url in a variable,I need to compare the current url with the stored url in php.Can you help me on this? – user2983060 Feb 21 '14 at 13:00