Using PHP if that matters, on a site https://www.example.com
. I send a Location
header of /member
with a 302 status. The redirect works fine, but the address bar in the browser displays https://www.example.com/member#_=_
.
What mechanism could be adding the #_=_
fragment?
This happens with both Chrome and Firefox. I've run the code under Xdebug and verified there's no fragment in the string passed to header()
, and use Chrome developer tools to verify that the header sent does not contain the fragment. And using Xdebug in the destination code, the fragment is not present in $_SERVER['REQUEST_URI']
, though I guess that never contains any fragment anyway.
For more context, which might or might not be helpful, this occurs when logging in to a Zend Framework 1.12 MVC application, when the login succeeds and redirects to the start page for the logged-in member. When the login method uses an email address and password, there is no fragment. When it uses OAuth2 through Facebook, I get the #_=_
fragment. When using OAuth2 through Google, I just get #
. That suggests to me that it's something in my code, but I don't even know how I could make those fragments show up in the address bar if I wanted to! And the code responsible for validating the login and doing the redirection is 90% common across all login methods - the OAuth-based methods just do the OAuth redirections to locate an entry in the user table, and once the entry is found the code is common to finding the entry by looking up an email address in the user table.
Edit: Thanks to a comment from Stephen Ostermiller I now have a JavaScript workaround I can put on the destination page to erase the fragment. And I verified that the fragment is not set by some rogue JavaScript somewhere, because it still shows up with JavaScript disabled. So it must be coming from the browser itself. But why, what would cause that? I can only guess it's related to the multiple redirections that happen with OAuth2, from my site to Facebook and then from Facebook back to my site, and then from my site to a different page on my site. Has anyone heard of such a thing? Interesting that the exact content of the fragment differs depending on which OAuth2 host I connect to, but the fragment is identical using Chrome, Firefox, MS Edge, and Internet Explorer 11. This is driving me crazy!
location.hash = '#_=_';