Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”
Reference - What does this error mean in PHP?
Notice: Undefined index: ac in C:\xampp\htdocs\CMS\includes\login.php on line 6
Notice: Undefined index: logged in C:\xampp\htdocs\CMS\includes\login.php on line 13
I am receiving the above Notices with the below code. How can I define my indexes? I understand there is a way to use ISSET but I am not sure how to do it with $_SESSION logged and USERS; since there are multiple values. How would I clear up the above errors in a correct manner without just suppressing notices/errors?
<?php
session_start(); // initialize session
include($_SERVER['DOCUMENT_ROOT'] .
'/CMS/CMSController.php');
if ($_POST["ac"]=="log") { /// do after login form is submitted
if ($USERS[$_POST["username"]]==$_POST["password"]) { /// check if submitted username and password exist in $USERS array
$_SESSION["logged"]=$_POST["username"];
} else {
echo 'Incorrect username/password. Please, try again.';
};
};
if (array_key_exists($_SESSION["logged"],$USERS)) { //// check if user is logged or not
echo "You are logged in.";
header('Location: /CMS/index.php');
} else { //// if not logged show login form
echo '<form action="login.php" method="post"><input type="hidden" name="ac" value="log"> ';
echo 'Username: <input type="text" name="username" />';
echo 'Password: <input type="password" name="password" />';
echo '<input type="submit" value="Login" />';
echo '</form>';
};
?>