Thanks for the reply Sir,I will show my complete code, i created two files,1.login.php (Simple HTML file In this file i included validate_login.php file at starting)2 validate_login.php (This is the main file where is check the codition and handling sessions) Login.php
<?php include ('validate_login.php'); ?><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>User Login --User Login Form! </title></head><body><div><center><h3><font face="Lucida Sans Unicode, Lucida Grande, sans-serif">Login <br /> ACCESS </font></h3><br /></center></div><br /><br /><br /><center><div id="form"><form action="login.php" method="post"><fieldset><legend> USER LOGIN</legend><p><div><label for="username">*USERNAME:</label><input type="text" name="username" /><br /><p></div><p><div><label for="username">*PASSWORD:</label><input type="password" name="password" /></div></p><br /><br /> <input type="submit" name="submit" value="Login" /> <input type="reset" name="reset" value="Reset" /></div></p></fieldset></form></center></body></html>
Validate_login.php
<?phpsession_start();if(isset($_SESSION['username'])) //if session is already there than redirect to index.php page { header('Location: index.php'); }?><?php if(isset($_POST['submit'])) { include('connection.php'); $username= $_POST['username']; $password= $_POST['password']; if(empty($username)) { echo "<b><font color='red'> ERROR: <br> "; echo "Username field can't be empty </font></b>"; } if(empty($password)) { echo "<br><b><font color='red'> ERROR: <br> "; echo "Password field can't be empty </font></b>"; } else { $password = md5($password); $sql = mysql_query("SELECT * FROM login WHERE username='$username' AND password='$password' LIMIT 1 ") or die ("Login Error " .mysql_error()); $num_rows = mysql_num_rows($sql); //echo "$num_rows"; if ($num_rows == 1) { $fetch=mysql_fetch_array($sql); extract($fetch); //echo "Current Logging User Is $username"; $_SESSION['username'] = $username; if(isset($_SESSION['username'])) { header('Location: index.php'); } } else { echo "<font color='red'>"; echo "<b>Invalid Credentials"; echo "</font></b>"; } }}?>
I am successfully redirect to index.php page, after removing else part, but on the login.php i am getting a session error. Notice: Undefined variable: _SESSION in /var/www/html/checklist/project/login/login.php on line 3