Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start(); //Starts A Session Unless There Already Is One.
- include 'dbconnectfilehere.php'; // Connects to the file which accesses the database.
- //Finds if there is a session called 'username', which starts once there logged in!
- if($_SESSION['username']) {
- // If there is a session, it takes them to home.php.
- header('Location: home.php');
- } else {
- //Else if there isn't a session, it see's if there $_POST values exist.
- if(isset($_POST['username']) && isset($_POST['password'])) {
- //If they do, it gets the username and password value.
- $username = mysql_real_escape_string($_POST['username']);
- $password = mysql_real_escape_string(md5($_POST['password']));
- //Now it does a mysql query to try and find the users.
- $query = mysql_query("SELECT * FROM `users` WHERE `username` = '{$username}' && `password` = '{$password}'");
- $num = mysql_num_rows($query);
- if($num == 0) { //If there isn't any rows, it means there information is wrong.
- echo "Wrong information!";
- } else { //If there is a row, it starts the session!
- $_SESSION['username'] = $username;
- $_SESSION['password'] = $password;
- echo "You are now logged in! Please click <a href='home.php'>here!</a>";
- }
- }
- ?>
- <form action="login.php" method="post">
- Username:<br />
- <input type="text" name="username" id="username" /><br />
- Password:<br />
- <input type="password" name="password" id="password" /><br />
- <input type="submit" value="Login" />
- </form>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement