0

How can we echo the complete url of the current page in PHP if the url is something like

http://www.abcd.in/emi-calc22.php#about

I have different tabs such as #about, #new on that page. I would like to identify the Div displayed on the page corresponding to the tabs with the help of the URL.

Varada
  • 16,026
  • 13
  • 48
  • 69

3 Answers3

2

You can not get the fragment part of URL through PHP.

Because it is not being sent to server hence you can not get it #about

Shakti Singh
  • 84,385
  • 21
  • 134
  • 153
2

The fragments can only be accessed on the client side (javascript) this is because when you press an url with a # in it you don't actually make a new request to the server but your browser processes it.

If you really want to get the # part to the server you will have to use ajax or a redirect function in javascript.

gnur
  • 4,671
  • 2
  • 20
  • 33
1

If you're using PHP on the page then why not pass the tab id as a query string, this will force a page refresh but you will have access to the URL's query string value server side via $_GET or $_REQUEST.

e.g. <a href="/samepage.php?tab=about">About Tab</a>

This could then be accessed in PHP via $_GET['tab'], then just use a switch statement or something to load the relevant div.

No need for complicated AJAX or javascript!!

Chris
  • 882
  • 1
  • 10
  • 22