Reputation: 17034
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.
Upvotes: 0
Views: 671
Reputation: 929
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!!
Upvotes: 1
Reputation: 4733
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.
Upvotes: 2
Reputation: 86336
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
Upvotes: 2