CREATE TABLE `user` ( `userid` INT(11) NOT NULL AUTO_INCREMENT, `username` VARCHAR(30) NOT NULL, `password` VARCHAR(30) NOT NULL, `fullname` VARCHAR(60) NOT NULL, PRIMARY KEY (`userid`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
<?php // Check connection { } ?>
<!DOCTYPE html> <html> <head> <title>Setting Up Cookie on User Login</title> </head> <body> <h2>Login Form</h2> <form method="POST" action="login.php"> <label>Username:</label> <input type="text" name="username"> <label>Password:</label> <input type="password" name="password"><br><br> <input type="checkbox" name="remember"> Remember me <br><br> <input type="submit" value="Login" name="login"> </form> <span> <?php echo $_SESSION['message']; } ?> </span> </body> </html>
<?php include('conn.php'); $username=$_POST['username']; $password=$_POST['password']; $query=mysqli_query($conn,"select * from `user` where username='$username' && password='$password'"); $_SESSION['message']="Login Failed. No user Found!"; } else{ //set up cookie $name_cookie = "user"; $value_cookie = $row['userid']; } $_SESSION['id']=$row['userid']; } } else{ $_SESSION['message']="Please Login!"; } ?>
<?php } include('conn.php'); ?> <!DOCTYPE html> <html> <head> <title>Setting Up Cookie on User Login</title> </head> <body> <h2>Login Success</h2> <?php echo $row['fullname']; ?> <br> <a href="index.php">Back</a> </body> </html>
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.