php通知未定义的索引会话

时间:2014-11-29 10:19:27

标签: php session indexing undefined notice

我有PHP注意:未定义的索引:错误日志中的langid 以下是它定义的代码,以便了解我的代码有什么问题

<?php 

if(($_SESSION['langid'])!="" ){

    $langid=$_SESSION['langid'];
    $_SESSION['langid']=$langid;


    if(isset($_REQUEST['langid']) && $_REQUEST['langid']!="" ){
        $langid=$_REQUEST['langid'];
        $_SESSION['langid']=$langid;
    }else{

    }

}else{
$langid=1;
$_SESSION['langid']=$langid;



if(isset($_REQUEST['langid']) && $_REQUEST['langid']!="" ){
    $langid=$_REQUEST['langid'];
    $_SESSION['langid']=$langid;
}else{

}
}

1 个答案:

答案 0 :(得分:0)

尝试:

<?php

if ( isset($_SESSION['langid']) )
{

    $langid=$_SESSION['langid'];
    $_SESSION['langid']=$langid;


    if(isset($_REQUEST['langid']) && $_REQUEST['langid']!="" ){
        $langid=$_REQUEST['langid'];
        $_SESSION['langid']=$langid;
    }else{

    }

}else{
$langid=1;
$_SESSION['langid']=$langid;



if(isset($_REQUEST['langid']) && $_REQUEST['langid']!="" ){
    $langid=$_REQUEST['langid'];
    $_SESSION['langid']=$langid;
}else{

}
}

?>

你将不会有关于警告的通知。但代码没有意义:

$langid=$_SESSION['langid'];
$_SESSION['langid']=$langid;

毫无意义