user2046091
user2046091

Reputation: 399

php print current url using $_GET

I am working arround get url in php

my url is

http://localhost/my__file.php?location=http://www.testsite.com/photo-gifts/custom_photo_necklace_oval_charm#design=68793492

when i am printing url using

$_GET['location'];

it prints only

http://www.testsite.com/photo-gifts/custom_photo_necklace_oval_charm

it not displaying me full url i.e. #design=68793492

Please help me on this

Upvotes: 0

Views: 423

Answers (5)

biztiger
biztiger

Reputation: 1487

You've to encode the location parameter.

First use php urlencode function to encode the url. Then pass the encoded value as a get parameter. "#" and "=" character need to encoded. It is always better to encode the whole URL.

For your example, Try

http://localhost/my__file.php?location=http%3A%2F%2Flocalhost%2Fmy__file.php%3Flocation%3Dhttp%3A%2F%2Fwww.testsite.com%2Fphoto-gifts%2Fcustom_photo_necklace_oval_charm%23design%3D68793492

Upvotes: 1

Er.KT
Er.KT

Reputation: 2860

You can not capture value after # in php but if you will pass encoded location value with # value you can get this value.

Upvotes: 0

Nagasaki
Nagasaki

Reputation: 58

replace # by %2C in you url or use urlencode

Upvotes: 1

deceze
deceze

Reputation: 522636

The last part separated by # is the fragment, which is never submitted to the server. You should URL encode the entire location value so special characters are preserved/lose their meaning.

Upvotes: 3

Ryan
Ryan

Reputation: 3582

The anchor tag (#example) won't be detected by PHP as it doesn't get passed on to the server...

You will need to use JavaScript window.location.hash

Upvotes: 1

Related Questions