I have a very simple page.php that should display all URL parameters. (I am having this issue in a more complex page but stripped it down to only this test, and the issue persists)
<?php
if (!isset($_SESSION)) {
session_start();
}
print_r($_GET);
?>
When I navigate directly to page.php?someProperty=testing , I sometimes get an empty array(), followed by working as expected on the second attempt, and every subsequent attempt. It seems to always fail the first time I make a request from the server after having been away for a while. I'm beginning to think it's something lower level. It's very difficult to debug because as soon as I observe it, it goes away. What could cause this?
Environment Info:
PS - I've read other similar posts, but in each case, someone had forgotten to initialize a session or something. I also made sure no whitespace or headers are set before the session is initialized
Update - When the page fails to read the URL parameters, the browser also immediately drops the query string from the location bar as well, reducing it to domain.com/page.php
Even if I manually type in the full address for page.php?test=test into the URL bar, it just immediately shortens, and the page outputs a blank array. Also, there is no rewriting of any kind enabled in Apache
Just for testing purposes, please also include something like print_r($_REQUEST);
and check its output.
Why is session_start inside the if isset of $_SESSION? You cannot read $_SESSION until the session is started. Perhaps this is causing your problem. Your code should start with session_start
<?php
session_start();
if (!isset($_SESSION)) {
// Do something
}
print_r($_GET);
?>