Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Start session
- session_start();
- // Include connection
- require('includes/connect.php');
- // Set default message to blank
- $message = "Please Login.";
- // Check if form is submitted
- if(isset($_POST['login'])) {
- $username = mysqli_real_escape_string($db,$_POST['username']);
- $password = mysqli_real_escape_string($db,md5($_POST['password']));
- // Set default session status
- $_SESSION['loggedIn'] = "false";
- // Execute query
- $login = "SELECT * FROM users WHERE username = '$username' AND password = '$password' LIMIT 1";
- if (!($result = mysqli_query($db,$login))) {
- die(mysqli_connect_error());
- }
- // Check for match if not display error message
- if (mysqli_num_rows($result) != 1) {
- $message = "<p class='error-msg'>Login Failed - Please try again!</p>";
- } else {
- // Build array of user data
- $userdata = mysqli_fetch_assoc($result);
- // Set sessions then redirect
- $_SESSION['loggedIn'] = "true";
- $_SESSION['user'] = $username;
- $_SESSION['name'] = $userdata['fullname'];
- $_SESSION['level'] = $userdata['level'];
- $_SESSION['code'] = $userdata['linkedcodes'];
- // Check user level and forward
- if($userdata['level'] == 1) {
- header('Location: /my/admin/');
- } else header('Location: /my/dashboard/');
- // Exit rest of script
- exit;
- }
- }
- ?>
- <html>
- <head>
- <title>myblackwellprint.co.uk | Customer Portal</title>
- <link rel="stylesheet" type="text/css" href="css/main.css" />
- </head>
- <body>
- <div id="login-page">
- <p class="login-welcome-msg"><?php echo $message; ?></p>
- <form id="login-form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
- <p style="margin-left:80px;"><label for="login">Username: </label><input id="login" class="login-fields" type="text" name="username" /><br />
- <label for="password">Password: </label><input id="password" class="login-fields" type="password" name="password" /><br /></p>
- <p style="margin-left:185px;"><input type="image" width="120" height="32" src="img/login_button.png" name="login" value="Login" /></p>
- </form>
- </div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment