Jimmyt1988
Jimmyt1988

Reputation: 21126

Getting a # out of your url in PHP

I know that $_GET["whatever"] gets ?whatever=*

Is there a way to get the # variable out of the url:

www.*.com#imsomething

? Can't find any results on google.

Upvotes: 0

Views: 286

Answers (3)

Arun David
Arun David

Reputation: 2784

No, that is not possible with a server side language... You need JavaScript to read that.

Upvotes: 0

Jeroen
Jeroen

Reputation: 13257

The part after # is a client-side part of the URL, it refers to an anchor within the HTML. Therefore, you can only retrieve everything before that.

Clients are not supposed to send URI-fragments to servers when they retrieve a document, and without help from a local application fragments do not participate in HTTP redirections.

~ Wikipedia: http://en.wikipedia.org/wiki/Fragment_identifier


You can use this Javascript code to get it's content client-side:

var hash = window.location.hash;

After grabbing it, you can of course send it to your server side code using jQuery's $.ajax or something similar.

Upvotes: 2

eis
eis

Reputation: 53462

No, there is not, since that is never sent to server side. That is something that is only visible on the browser.

You can read it with javascript and then submit to server side if you really want to, but normally it doesn't get sent. With javascript, you can read window.location.hash to get the value.

Upvotes: 2

Related Questions