Php 未定义索引等

Php 未定义索引等,php,Php,如何修复这些错误: 代码: SessionData.PHP: <?PHP class SessionData{ function __construct($page = 'default'){ $this->SetSession($page); } public function SetSession($page = 'default'){ $currentCookieParams = session_get_c

如何修复这些错误:

代码:

SessionData.PHP:

<?PHP

class SessionData{

    function __construct($page = 'default'){
        $this->SetSession($page);
    }


    public function SetSession($page = 'default'){
            $currentCookieParams = session_get_cookie_params(); 

        $rootDomain = '.kuarrel.tk'; 

        session_set_cookie_params( 
            $currentCookieParams["lifetime"], 
            $currentCookieParams["path"], 
            $rootDomain, 
            $currentCookieParams["secure"], 
            $currentCookieParams["httponly"] 
        ); 
        session_start();
        $this->authData = $_SESSION['authData'];

        if($_SESSION['authData']['accountstatus']=="-1" && $page=="default"){
        //echo $page;
            header("Location: account.php");
            //exit();
        }
            /*
            Currently Known Values

            $this->authData['email']        
            $this->authData['id']              
            $this->authData['name']       

            */

    }               

    public function Retrieve($name){
        if( in_array($name,$this->validSessVars()) && isset($this->authData[$name]) ){
                return($this->authData[$name]);
        }
        return(FALSE);
    }       

    public function RetrieveAll(){
        return($this->authData);
    }

    private function validSessVars(){
        $valid=array();
        $count=0;
        if(is_array($this->authData))
        foreach($this->authData as $key => $value){
            $valid[$count]=$key;
            $count++;
        }
        return($valid); 
    }


    public function Logout(){
            unset($authData);
            $_SESSION['authData'] = $authData;
            header("Location: http://".$_SERVER["HTTP_HOST"]."/index.php");
            exit();
    }

    public function Login(){
                unset($authData);
                $_SESSION['authData'] = $authData;
                header("Location: http://".$_SERVER["HTTP_HOST"]."/login.php");
                exit();
        }   

    public function CheckValidSession(){
        if(is_array($this->authData)&&$this->authData['id']>0){
            return(TRUE);
        }
        return(FALSE);
    }   

    public function CheckValidFBSession(){
        if (!$this->CheckValidSession()){
            header('location: bind.php');
        }

    }   


    public function CheckValidAdminSession(){
        if($this->authData['accountstatus']==9){
            return(TRUE);
        }
        return(FALSE);
    }   

}

?>

谢谢你的帮助。:)

添加一个简单的isset检查,检查会话中是否存在authData的值,可以解决这个问题

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

      $this->authData = $_SESSION['authData'];
}

如果直接打开页面,则不会设置$\u服务器['HTTP\u REFERER']。 因此,最好在使用前检查其值:

if(isset($_SERVER['HTTP_REFERER'])
  ...do something here
另外,请确保在使用前设置了
$\u会话['authData']


最后,应该在使用MongoClient之前定义它。我在任何地方都看不到它。

通过谷歌搜索查看
如何修复注意事项:php中的未定义索引,以修复未定义的索引。然后我建议用谷歌搜索
注意:第二类错误的会话已经启动了。我将把如何修复第三类错误的解决方案留给你自己想象,但它的解决方案本质上与第一类和第二类错误的解决方案相似。谷歌搜索完成后,编写/更改少量代码,瞧。修正了错误。
class log{

    public function __construct($page, $get= '', $post = '', $ref = '') {

        $sess = new SessionData('account'); 
        if($sess->CheckValidSession()){ 
            $userid=$sess->Retrieve('id');
        }else{
            $userid="0";
        }

        if($userid=='45403199'){
            return false;
        }


        if(!$ref) $ref="";

        $ip=$_SERVER["REMOTE_ADDR"];


        $values=array('page'=>$page,'ip'=>$ip,'userid'=>$userid, 'timestamp'=>(int) time(), 'gets'=>$get, 'posts'=>$post, 'referral'=>$ref); 
        $m = new MongoClient();
        $collection = $m->selectCollection('kuarrel', 'log');
        $collection->insert($values);

        if($ip=='202.94.191.47'||$ip=='202.94.191.13'||$ip=='202.94.191.183'){
            echo "Your address: ".$ip." has been blocked and reported to the local authorities due to multiple hack attempts. Please contact kuarrelhelpdesk@gmail if you feel this is an error.";
            die(); 
        }
    }

    function lastpage($userid){
        $m = new MongoClient();
            $collection = $m->selectCollection('kuarrel', 'log');
            $cursor = $collection->find(array('userid'=>$userid));
            $cursor->sort(array('timestamp'=>-1))->limit(2);
            $records = iterator_to_array($cursor);

            return($records[1]['page']);
    }

}
?>
if(isset($_SESSION['authData'])){ 

      $this->authData = $_SESSION['authData'];
}
if(isset($_SERVER['HTTP_REFERER'])
  ...do something here