Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //First check to see if you are logged in
- if ($_SESSION['logged'] == 1) {
- echo "<h2>Info</h2><p>You are already logged in!</p>";
- } else {
- //Form Submittion
- if ($_GET['action'] == "submit") {
- //Form Inputs
- $Password = $_POST['Password'];
- $Username = $_POST['Username'];
- //Query the database and select the Username by password
- $query = "SELECT * FROM users WHERE Password = '$Password'";
- $result = mysql_query($query);
- //If it returns a result, assign the sessions username as whats in the database
- if (@mysql_num_rows($result) > 0) {
- session_unset();
- session_start();
- while ($row = mysql_fetch_assoc($result)) {
- $_SESSION['username'] = $row['Username'];
- }
- //make this variable 1 meaning you are logged in
- $_SESSION['logged'] = 1;
- //Content after submittion
- echo "<h2>Info</h2><p>Logged in!</p>";
- echo "<META HTTP-EQUIV=Refresh CONTENT='0; URL=index.php'>";
- } else {
- //Bad credentials
- echo "<h2>Info</h2><p>Incorrect Username or Password</p>";
- echo "<META HTTP-EQUIV=Refresh CONTENT='1; URL=index.php?x=login'>";
- }
- } else {
- ?>
- <form method="post" action="index.php?x=login&action=submit">
- <p>
- Username - <input type="text" name="Username" class="Input" style="width: 100px; height: 13px;" /><br />
- Password - <input type="password" name="Password" class="Input" style="width: 100px; height: 13px;" /><br />
- <input type="submit" name="submit" class="Button" value="Login" /><br />
- </p>
- </form>
- <?php } } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement