Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'connect.php';
- session_start();
- if (isset($_POST['submit'])) {
- $username = $_POST['username'];
- $password = $_POST['password'];
- if ($username&&$password)
- {
- $query = mysql_query("SELECT * FROM users WHERE username ='$username'");
- if($numrows!==0) {
- while($row = mysql_fetch_assoc($query)) {
- $numrows = mysql_num_rows($query);
- $expire= time()+60*60*24*30;//30days
- setcookie("uid",$row['id'], $expire);
- setcookie("username", $row['username'], $expire);
- // setcookie("password", $_POST['password'], $expire);
- $dbusername = $row['username'];
- $dbpassword = $row['password'];
- }
- if($username==$dbusername&&md5 ($password)==$dbpassword) {
- header("location: index.php");
- $_SESSION['username'] = $username;
- echo "Logged in. as <b>".$row['username']."</b>";
- }
- else
- $_SESSION['message'] = 'Your password is incorrect!';
- }
- else
- $_SESSION['message'] = 'User does not exist';
- }
- mysql_close($connection);
- }
- ?>
- <html>
- <body>
- <!-- <link href="//db.onlinewebfonts.com/c/a4e256ed67403c6ad5d43937ed48a77b?family=Core+Sans+N+W01+35+Light" rel="stylesheet" type="text/css"/> -->
- <link rel="stylesheet" href="form.css" type="text/css">
- <div class="body-content">
- <div class="module">
- <h1>Login</h1>
- <form class =form action="/login.php" method="post" enctype="multipart/form-data" autocomplete="on">
- <div class="alert alert-error"><?= $_SESSION['message'] ?></div>
- <input type="text" placeholder="Username" name="username" value="<?php if(isset($_COOKIE['username'])) echo $_COOKIE['username']; ?>" required>
- <input type="password" placeholder="Password" name="password" required>
- <!-- value="<?php if(isset($_COOKIE['password'])) echo $_COOKIE['password']; ?>" -->
- <input type="submit" value="Login" name="submit" class="btn btn-block btn-primary" />
- <a class="btn"href="form.php">Register </a> If you haven't registered yet
- <style>
- h1 {text-align:center}
- </style>
- </form>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement