0

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

user2046091
  • 369
  • 3
  • 4
  • 12
  • 1
    `#design=68793492` is *not* part of the `location` parameter. If it should, then the URL is invalid. There's not much you can do from the PHP side that consumes the data. – Álvaro González May 03 '13 at 09:16

5 Answers5

3

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.

deceze
  • 510,633
  • 85
  • 743
  • 889
1

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

Ryan
  • 3,552
  • 1
  • 22
  • 39
  • http://stackoverflow.com/questions/16354426/php-get-url-content/16354457?noredirect=1#comment23429695_16354457 – Ryan May 03 '13 at 09:13
  • 1
    The question doesn't ask for $_SERVER['REQUEST_URI']. OP is simply trying to pass a url as a GET parameter. – biztiger May 03 '13 at 09:18
1

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
biztiger
  • 1,447
  • 4
  • 23
  • 40
1

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

Nagasaki
  • 60
  • 2
  • 16
0

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

Er.KT
  • 2,852
  • 1
  • 36
  • 70