Undefined variable _GET

Hi guys,

I got a problem with a php webapplication. It stops working after 10-20 hours (not always the same time) for no reason because $_GET is not defined.

The request looks like:

h77p://host/index.php?id=1
the index file has a lil code snippet like:

Code:

if (isset($_GET['id']) && is_numeric($_GET['id'])) { 
    $id = intval($_GET['id']); 
} else { 
    die('wrong id'); 
}

A var_dump of $_GET returns NULL. A var_dump of $_SERVER shows the REQUEST_METHOD is GET and the QUERY_STRING is id=1. A var_dump() of $_REQUEST shows id => 1, so it’s only $_GET that isn’t working.

When that happens it happens for all webapplications on the server and for all users. After restarting the webserver everything is working again for some hours…

System is Windows 2008 R2, Apache 2.4.18 32 Bit/PHP 7.0.5 32 Bit.

No errors inside the php_errors.log, errors.log of httpd or the syslogs.

Configs are pretty much standard.

php.ini:

httpd.conf

Hi @aLpenbog,

Welcome to the forum.

I have no knowledge of Windows Servers but you could try this and see if you manage to find the id giving the problem:

# domain_name.com?DEBUG=TEST&id=123
    $DEBUG = ( isset($_GET['DEBUG']) && 'TEST'===$_GET['DEBUG'] ) ? TRUE : FALSE;
    if($DEBUG):
        echo '<pre>'; var_dump($_GET); echo '</pre>';
    enddif;

    if (isset($_GET['id']) && is_numeric($_GET['id'])) {
        $id = intval($_GET['id']);
        var_dump($id);
    } else {
        die('wrong id');
    }

Please note:
The above script starts and finishes with three backticks on a new line.

Enclosing PHP script within a sentence requires a singe backtick _SERVER[''REQUEST_URI] otherwise underscores and other syntax will be removed :frowning:

I cleaned up the post so $_SERVER and the like are showing properly.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.