Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @author Jason
- * @copyright 2011
- */
- session_start();
- include 'config.php';
- if ( isset( $_SESSION['username'] ) && isset( $_SESSION['password'] ) ) {
- echo '
- Welcome <strong>'. $_SESSION['username'] .'</strong> !
- <br />
- <a href="logout.php">Logout</a>
- ';
- } else {
- if ( isset( $_POST['submit'] ) ) {
- $username = $_POST['username'];
- $password = $_POST['password'];
- if ( $username && $password ) {
- $query = mysql_query( " SELECT * FROM users WHERE `username` = '$username' " );
- $numrows = mysql_num_rows( $query );
- if ( $numrows ) {
- while ( $r = mysql_fetch_assoc( $query ) ) {
- $db_username = $r['username'];
- $db_password = $r['password'];
- }
- if ( $db_username == $username && $db_password == $password ) {
- $_SESSION['username'] = $username;
- $_SESSION['password'] = $password;
- echo "<div style='background-color: lightgreen'><meta http-equiv='refresh' content='2'>You have now been logged in, please wait while you're being redirected.</div>";
- } else {
- echo "<div style='background-color: red'>Incorrect password.</div>";
- }
- } else {
- echo 'Incorrect username.';
- }
- } else {
- echo 'Please enter a valid username and password.';
- }
- } ?>
- <form method="POST" action="">
- Username: <input type="text" name="username" value="<?php echo $_POST['username'] ?>"/> <br />
- Password: <input type="text" name="password"/> <br />
- <input type="submit" name="submit"/>
- </form>
- <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement