I'm facing a very strange behavior and hope to get your help and the solution or explenation for it.
I do use a very simple code on a page:
// start a session
if( !session_id() )
session_start('');
// write current url in session to prepare redirect after login
$_SESSION['url_before_login'] = $_SERVER['REQUEST_URI'];
On the same page I do load a favicon, which currently is missing. So, on the console of the browser i get this error message:
GET https://my.domain.ltd/assets/favicon/apple-touch-icon.png [HTTP/2 404 Not Found 141ms]
This is fine. But, the strange behavior is, my variable $_SESSION['url_before_login']
does not have the $_SERVER['REQUEST_URI']
of my page but the $_SERVER['REQUEST_URI']
of the missing file.
When I output the $_SESSION['url_before_login']
I do get /assets/favicon/apple-touch-icon.png
instead of /folder/sub-folder/
.
If there is no loading error and no missing file, the $_SESSION['url_before_login']
shows me the right URI.
Does anyone know this behavior and has a solution how to fix this (beside making sure not to have a missing file ;-)).
I guess you have a
.htaccess
file that reroutes all requests to the PHP file, meaning that for every request you session variable is rewritten:The browser makes several requests for favicons, you can't prevent that, so this will interfere with your session vars if everything goes through the same script.
So, you have some options:
a. you change your
.htaccess
file so that all requests for "favicon" are redirected to another path SO search: redirect favicon request:b. change you PHP file to something like this:
c. put some favicons on your server, or use a hack: SO: How to prevent favicon.ico requests?