Fatal error when using isset

Asked

Viewed 1,078 times

2

I have a code that’s giving error and I can’t fix it. The chunk of file giving error is this:

if(isset(!($_SESSION['username']) && ($_COOKIE['remember'] == "remember"))){

$cname = FilterText($_COOKIE['rusername']);
$cpass_hash = $_COOKIE['rpassword'];


$csql = mysql_query("SELECT password,id FROM users WHERE username = '".$cname."' LIMIT 1") or die(mysql_error());
$cnum = mysql_num_rows($csql);

    if($cnum < 1){
        setcookie("remember", "", time()-60*60*24*100, "/"); setcookie("cookpass", "", time()-60*60*24*100, "/");
        setcookie("rusername", "", time()-60*60*24*100, "/"); setcookie("cookpass", "", time()-60*60*24*100, "/");
        setcookie("rpassword", "", time()-60*60*24*100, "/"); setcookie("cookpass", "", time()-60*60*24*100, "/");
    } else {

        $crow = mysql_fetch_assoc($csql);
        $correct_pass = $crow['password'];

        if($cpass_hash == $correct_pass){
            $_SESSION['username'] = $cname;
            $_SESSION['password'] = $crow['password'];
            $sql3 = mysql_query("UPDATE users SET ip_last = '".$remote_ip."' WHERE username = '".$cname."'");
            header("location: me"); exit;
        } else {

            setcookie("remember", "", time()-60*60*24*100, "/"); setcookie("cookpass", "", time()-60*60*24*100, "/");
            setcookie("rusername", "", time()-60*60*24*100, "/"); setcookie("cookpass", "", time()-60*60*24*100, "/");
            setcookie("rpassword", "", time()-60*60*24*100, "/"); setcookie("cookpass", "", time()-60*60*24*100, "/");
        }
    }
}

And the mistake is this:

Fatal error: Cannot use isset() on the result of an Expression (you can use "null !== Expression" Instead)

1 answer

3

Bug says you can’t use isset() with the return of something, in this case the code below the value of $_SESSION['username'] is denied and this is the value passed to the isset().

if(isset(!($_SESSION['username'])

Modify your code to:

if(!isset($_SESSION['username']) && ($_COOKIE['remember'] == "remember")){

Browser other questions tagged

You are not signed in. Login or sign up in order to post.