du7618841
2013-09-11 17:26
浏览 17
已采纳

修复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).
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • doupu2722 2013-09-11 17:37
    已采纳

    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 :-)

    已采纳该答案
    打赏 评论
  • doudou521125 2013-09-11 17:28

    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']))
    
    打赏 评论
  • dtpf76658 2013-09-11 17:30

    $_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)
    
    打赏 评论
  • douyi8760 2013-09-11 17:32

    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
        }
    
        }
    
    打赏 评论

相关推荐 更多相似问题