-1

I am trying to pass some parameters after # in the url like http://developer.rohitkhatri.com/test.php#embed=sdkhfjshdkfhhjk, But I don't know how to access it, I tried many solution from the stackoverflow, here are some examples what I've tried:

$_SERVER['REQUEST_URI'] gives me /test.php
$_SERVER['QUERY_STRING'] gives empty string
$_SERVER['HTTP_REFERER'] gives empty string

also tried printing the whole $_SERVER array but I did not find anything useful.

Any help is appreciated.

Rohit Khatri
  • 1,980
  • 3
  • 25
  • 45
  • use query string instead of # ==> http://developer.rohitkhatri.com/test.php?embed=sdkhfjshdkfhhjk – Aman Maurya Aug 08 '16 at 07:01
  • Part of string after `#` never passed to server unless you create some javascript magik. – u_mulder Aug 08 '16 at 07:01
  • If you really need '#' then you should use JS to make an Ajax call to test.php passing as parameters whatever you have afther the hash – Dan Bizdadea Aug 08 '16 at 07:03
  • http://stackoverflow.com/questions/2317508/get-fragment-value-after-hash-from-a-url-in-php $url=parse_url('http://developer.rohitkhatri.com/test.php#embed=sdkhfjshdkfhhjk'); echo $url["fragment"]; you get "embed=sdkhfjshdkfhhjk" then u can explode by '=' – Tanvir Hasan Aug 08 '16 at 07:06
  • Actually I'm trying to pass some parameters with `bit.ly` shortened url, because when I pass query string with `bitly` url, It doesn't provide them on the server side, but when I pass anything after `#`, It's available on the redirected url. Is there any other way of achieving this, I would be thankful :-) – Rohit Khatri Aug 08 '16 at 07:07

2 Answers2

1

Well, there's no way to achieve this, because the part you are trying to access using the php, never goes to the server, what you can do is, just grab the part using the javascript and send it the the server.

Like there can be a middle page, which will redirect to the final url, and while redirecting, It can grab the part after # and send it using ajax.

Daisy Saxena
  • 160
  • 5
-1

The browser doesn't send anything that comes after the hash(#) to the server because it is resolved within the browser. You can try by mentioned code.

$hash = '<script>document.write(document.location.hash)</script>';
echo $hash;

output :

//#embed=sdkhfjshdkfhhjk
Jakir Hossain
  • 2,457
  • 18
  • 23
  • How does this help? I'm not getting the value in `$hash` variable. – Rohit Khatri Aug 08 '16 at 10:59
  • It will show "#embed=sdkhfjshdkfhhjk". If you want to get value after '=' sign than you have 'split' or 'explode' – Jakir Hossain Aug 08 '16 at 11:51
  • So you are saying that php variable `$hash` will hold the `#embed= sdkhfjshdkfhhjk` part, right? and then I can use that php variable to load the page, Is this you are trying to say? – Rohit Khatri Aug 08 '16 at 12:34