Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $conn = mysqli_connect("localhost", "root", "", "members");
- if(!$conn) {
- die("Oops! Something went wrong. Please try again later...");
- }
- $error = false;
- if($_SERVER["REQUEST_METHOD"] == "POST") {
- if(empty($_POST["username"])) {
- $error = true;
- echo "<h2 style='color:red; font-family:bold;'>Please enter your Username!</h2>";
- } else {
- $error = false;
- }
- if(empty($_POST["password"])) {
- $error = true;
- echo "<h2 style='color:red; font-family:bold;'>Please enter your Password!</h2>";
- } else {
- $error = false;
- }
- if(!$error && $_POST["username"] != "" && $_POST["password"] != "") {
- $pass = trim($_POST["password"]);
- $pass = strip_tags($pass);
- $pass = htmlspecialchars($pass);
- $password = hash("sha256", $pass);
- $username = trim($_POST["username"]);
- $username = strip_tags($username);
- $username = htmlspecialchars($username);
- $sql = "SELECT * FROM users WHERE username = '$username'";
- $result = mysqli_query($conn, $sql);
- $row = mysqli_fetch_array($result);
- $rowcount = mysqli_num_rows($result);
- if ($rowcount == 1 && $password == $row["password"]) {
- $_SESSION["id"] = $row["id"];
- $_SESSION["username"];
- header("location: home.php");
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF=8"/>
- <meta name="viewport" content="width=device-width"/>
- <title>Login System</title>
- <link href="loginstyles.css"/>
- </head>
- <body>
- <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
- <span id="loginHeader">Login</span>
- <br><br>
- <input type="text" name="username" placeholder="Username"/>
- <br>
- <input type="password" name="password" placeholder="Password"/>
- <br>
- <button type="submit" name="submit" class="btn-primary">Login</button>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement