0

I am getting this "Notice: Undefined index: id" error message for my login system. I have tried several things to fix this but i have had no luck, i have used the most obvious solution, the isset function but i have had no luck. Please help.

This is the error message... Notice: Undefined index: id in /Applications/MAMP/htdocs/project/functions.php on line 6. The code for the functions page is below, if i need to include other pages please let me know.

Thanks in advance

<?php



function is_logged_in(){
    if($_SESSION['id'] or $_COOKIE['id']){
        if($_COOKIE['id'] and !$_SESSION['id']) $_SESSION['id'] = $_COOKIE['id'];
        return $_SESSION['id'];
    }
    else
        return false;
}
function redirect_if_logged_in(){
    if(is_logged_in()){
        echo 'You are logged in. Redirecting!!';
        redirect2home();
    }
}
function redirect_if_not_logged_in(){
    if(!is_logged_in()){
        echo 'You are not logged in. Redirecting!!';
        redirect2home();
    }
}

function redirect2home(){
    die('<META HTTP-EQUIV="refresh" CONTENT="5; URL=personal.php">');
}

?>
5
Contributors
4
Replies
42
Views
2 Years
Discussion Span
Last Post by bugz313
0

Is your session ID set? try echoing for the value first if your really getting it.your file should start with a session_start() function for your session variable to work try adding it at line 2

0

try to use isset(), to check if there is a value assign to $_SESSION

 if(isset($_SESSION['id']) or isset($_COOKIE['id'])){
 // do whatever you want
 }
0

where do you have your start_session() function?? it has to be the first thing you do before anything else, so before you are including this php in any file.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.