Hey, I am trying to use this simple php login script and it returns some error on row 6 ("if ($_SESSION["valid_user"]) " row. It does however login properly, with right user and email ofcourse but returns the error "Notice: Undefined index: valid_user in c:\server\htdocs\login.php on line 6" Any master php dev up for fixing this in a sec Heres the login.php code, im using 3 more php files ( reg.php, welcome.php, logout.php) <?php session_start(); // This part sets up the connection to the // database (so you don't need to reopen the connection // again on the same page). if ($_SESSION["valid_user"]) { // User not logged in, redirect to login page Header("Location: welcome.php"); } // is selected. if (isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; $file = file_get_contents("data.txt"); if(strstr($file, "$name||$email")) { $_SESSION["valid_user"] = $_POST["name"]; $_SESSION["valid_time"] = time(); // Redirect to member page Header("Location: welcome.php"); } else { // Login not successful print '<script> alert ("Sorry! You have entered a Invalid Login Id or Password."); window.location="login.php"; </script>'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Login Page Test Script.</title> </head> <body> <form method="post" action="login.php" > enter name: <input type="text" name="name" /> <br/> <br/> enter email: <input type="text" name="email" /> <br/> <br/> <input type="submit" value="login" name="submit"/> </form> </body> </html>
Replace: if ($_SESSION["valid_user"]) PHP: With this: if (isset($_SESSION['valid_user'])) PHP: Hope that helps. Tim
Hi, I am a PHP developer.I go through your message and i can resolve it if you are interested then let me know