Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- // Check if the HTML form was submitted
- if( !empty( $_POST["username"] ) ){
- // The form was submitted
- $username = $_POST["username"]; // The submitted input values
- $password = $_POST["password"];
- // Connect to your mysql server
- mysql_connect("localhost", "username", "password");
- mysql_select_db("users_database");
- $results = mysql_query("SELECT * FROM USERS WHERE username = '$username' AND password = '$password'");
- // If there are more then 0 results then the username and password are correct
- if( mysql_num_rows( $results ) ){
- // Successful login, lets set the session
- $_SESSION["username"] = $username;
- } else {
- // ELse output an error
- echo "username and password are wrong fool";
- }
- }
- // Check to see there is an active session
- if( !empty( $_SESSION["username"] ) ){
- echo "You are currently logged in";
- }
- ?>
- <html>
- <body>
- <!-- This form will submit to the same page its on which will trigger the php script above -->
- <form action="" method="post">
- <label>Username</label>
- <input type="text" name="username" />
- <label>Password</label>
- <input type="text" name="password" />
- <input type="submit" value="Login" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement