I have a user log in which shows a users ID once logged in. The code works really well. However on both the header.php and the login.php I get a notice:
Notice: Undefined index: id in D:wampwampwwwstuffuserlogin2header.php on line 6
Both are the same, undefined index: id.
This is coming from my session ID but I’m not sure how to set the session ID before logging in without effecting my log out.
header.php:
[code=php]
<?php
session_start();
include(“connection.php”);
if ($_SESSION[‘id’] != “”) {
echo “Welcome, “.$_SESSION[‘id’];
echo “<br><form action=’logout.php’ method=’post’><input name=’Logout’ type=’Submit’ value=’Logout’ /></form>”;
}
else{
// show login box
?>
<html>
<head>
<title>Home Page</title>
<head>
<body>
Welcome to the website.<br />
Please log in.<br /><br />
<form name=”frmLogin” action=”login.php” method=”post”>
Username :<br>
<input name=”txtid” type=”text” />
<br/>
Password :<br>
<input name=”txtpwd” type=”password” /><br>
<input type=”submit” value=”Login” name=”btnlogin” />
</form>
</body>
</html>
<?php
}
?>
Login.php:
[code=php]
<?php
session_start();
include(“validate.php”);
include(“connection.php”);
if ($_SESSION[‘id’] != ” or validatelogin($_POST[‘txtid’],$_POST[‘txtpwd’]) == true){
echo “<head><meta HTTP-EQUIV=’REFRESH’ content=’0; url=index.php’></head>”;
}
else
{
echo “You have posted incorrect log in data you will automatically be redirected”;
echo “<head><meta HTTP-EQUIV=’REFRESH’ content=’10; url=index.php’></head>”;
}
?>
I know the code works, but a notice still means its not well written, any advice would be greatly appriciated.
many thanks
Aravona