I was learning to make a simple login form from a book and I'm having some problems.

When I run the login.php script in my browser and enter the correct username and password(or even a wrong input)..it displays the error

> 
> (Notice: Undefined variable: \_SESSION in C:\Program Files (x86)\EasyPHP-DevServer-13.1VC9\data\localweb\rassal\login.php on line 8).
> 
> 
> 

If I enter the correct combination, the user is logged in ..but still the same notice appears and the script redirects back to the login.php page.

How can I edit the script to make it work perfectly ? Like it should accept the login and then take to a page(in session).

Here are the codes

login.php

```
<?php
$username = (isset($_POST['username'])) ? $_POST['username'] : '';
$password = (isset($_POST['password'])) ? $_POST['password'] : '';
$redirect = (isset($_REQUEST['redirect'])) ? $_POST['redirect'] : 'secret.php';

if(isset($_POST['submit']))
{
if(!isset($_SESSION['logged']) && $_SESSION['logged']!=1)
{
if(!empty($username) && $username == 'uname' && !empty($password) && $password = 'ppas')
{
$_SESSION['username']=$username;
$_SESSION['logged']=1;
header('Refresh: 5; URL = '.$redirect);
echo "Redirecting";
die();
}
else
{
$_SESSION['username']='';
$_SESSION['logged']=0;
echo "You entered a wrong combination of username and password";
}
}
}
?>
<html>
<head>
<title>Login </title>
</head>
<body>
<form action="login.php" method="post">
<table>
<tr>
<td>Username :</td>
<td><input type="text" name="username" value="<?php echo $username; ?>" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" value="<?php echo $password; ?>" /></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Log In" /></td>
</tr>
</table>
</form>
</body>
</html>

```

Here's the auth.inc.php

```
<?php
session_start();

if(!isset($_SESSION['logged']) && $_SESSION['logged']!=1)
{
header('Refresh: 5; URL=login.php?redirect=' . $_SERVER['PHP_SELF']);
echo "You'd be now redirected to the login page ";
}
die();
?>

```

and here's secret.php(file to be shown when the user has successfully logged in )

```
<?php
require ('auth.inc.php');
?>
<html>
<head>
<title>Logged IN </title>
</head>
<body>
<h2>You're now logged in </h2>
</body>
</html>

```