Undefined index at session in php

i want to make a function to check login or not. but when i run, there’s an error. the error is undefined index email and pass at the session variable. please help


function cek_login(){
    $hasil = 0;

    $mail = $_SESSION['email'];
    $pass = $_SESSION['pass'];

    if (!empty($mail) and !empty($pass)){
        $hasil = 1;

    return $hasil;

Should that be “mail” or “email”?

Try this and view the session values:

 $hasil = 0;

 echo "<pre>";
 print_r( $_SESSION);
 echo "</pre>";

  $mail = isset($_SESSION['email']) ? $_SESSION['email'] : NULL;
  // same for $pass

Tediously tapped on a tablet :frowning:

Did you use session_start() somewhere else other then header.php ?
If YES, you have to remove it from either of the page

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.