修复Index.php第6行错误未定义索引:注销[关闭]

Undefined index: logout in F:\xampp\htdocs\xxx\index.php on line 6 This is the index.

<?php
session_start();
date_default_timezone_set('Europe/Paris'); 

// LOGOUT
if($_GET['logout']==1).

i suggestion to you, first create a function ex:

<?php
function get_request($name, $default = ''){
    if(isset($_REQUEST[$name])){
        if($_REQUEST[$name] != ''){
            return $_REQUEST[$name];
        }else{
            return $default
        }
    }else{
        return $default
    }
}
?>

Now! you can use

<?php
session_start();
date_default_timezone_set('Europe/Paris'); 

// LOGOUT
if(get_request('logout', 0) == 1)

or for simple use, you can write:

// LOGOUT
if(isset($_GET['logout']) && $_GET['logout'] == 1)

regards :-)

If a url parameter is not set and you try to reference it from the $_GET array it will generate this notice. To avoid this use the isset() function instead.

if(isset($_GET['logout']))

$_GET is an array containing all the GET parameters

When you acces the page from this URL:

www.myphppage.php?para1=1&para2=2

$_GET will be

Array ( [para1] => 1 [para2] => 2 )

Try checking for the existence of 'logout' before checking the value:

if(isset($_GET['logout']) && $_GET['logout'] == 1)

You have to check if $_GET['logout'] is set via the isset() function

  <?php
    session_start();
    date_default_timezone_set('Europe/Paris'); 

    // LOGOUT
    if(isset($_GET['logout'])) {

    if($_GET['logout']==1) {
    // action
    }

    }