Jump to content

Ashish Sood

Members
  • Posts

    79
  • Joined

  • Last visited

Everything posted by Ashish Sood

  1. 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
  2. I want to know one more thing, after successfully login my page will be redirect to index.php, But if someone open again login.php he also should be redirect to index.php. please guys tell me what condition i need to put in login.php page. I tried below, but after again open login.php, it am getting the error. <?phpif(isset($_SESSION['username'])) { header('Location: index.php'); } else { header('Location: login.php'); }?> ERROR The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies.
  3. Thanks More Human Than Human, Its working for me now. :Happy:
  4. HI ,I am facing a problem with my logout form after destroying a session my page is not redirected to login.php, even after refresh the same page logout.php page i am gettting Notice: Undefined index: username in /var/www/html/checklist/project/login/logout.php on line 4 username, That mean my session is destroyed, but dont know why i will not get redirected..please guys advice me what i am doing wrong in this , Please find my code below. <?phpsession_start();if(isset($_SESSION['username'])){ session_destroy(); header("location: login.php"); }?>
×
×
  • Create New...