Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php session_start(); //using PHP sessions
- require 'connect.php';
- include 'header.inc.php';
- if ($_POST['login']=='Submit') {
- $username= $_POST['username'];
- $password= $_POST['password'];
- //store the username
- $_SESSION['username']=$username;
- $sql="SELECT * FROM users WHERE username='$username' AND password='$password'";
- $result = $conn->query($sql) or die(mysqli_error());
- $count = $result->num_rows;
- if($count==1) // If there is a match..
- {
- header("Location:overviewpage.php"); // go to overview page
- // $_SESSION["username"] = $username; // Creates a cookie saving the username
- // $_SESSION["loggedIn"] = true; // Creates a cookie saying the user is logged in
- // header("Location:ProtectedPage.php");
- }else{ // If invalid information was entered
- // header("Location:overviewpage.php"); // Lastly, redirect back to login page
- echo 'invalid username or password. Please try again.';
- echo printLoginForm();
- }
- }
- else {
- printLoginForm();
- }
- function printLoginForm() {
- echo '<form id="form1" name="form1" method="post" action="index.php">
- <p>
- <label for="username">username</label>
- <input type="text" name="username" id="username" />
- <label for="password">password</label>
- <input type="password" name="password" id="password" />
- <input type="submit" name="login" id="login" value="Submit" />
- </p>
- </form>';
- }
- ?>
- <p> </p>
- </body>
- </html>
Add Comment
Please, Sign In to add comment