Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $DB_HOST = 'localhost';
- $DB_USER = 'cyberwol';
- $DB_PASS = 'm74c3tg^vxmpH8t7aVj9';
- $DB_NAME = 'phplogin';
- $con = mysqli_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
- if ( mysqli_connect_errno() ) {
- die ('Failed to connect to MySQL: ' . mysqli_connect_error());
- }
- if ( !isset($_POST['username'], $_POST['password']) ) {
- die ('Username and/or password does not exist!');
- }
- if ($stmt = $con->prepare('SELECT id, password FROM accounts WHERE username = ?')) {
- $stmt->bind_param('s', $_POST['username']);
- $stmt->execute();
- $stmt->store_result();
- if ($stmt->num_rows > 0) {
- $stmt->bind_result($id, $password);
- $stmt->fetch();
- if ($_POST['password']==$password) {
- $_SESSION['loggedin'] = TRUE;
- $_SESSION['name'] = $_POST['username'];
- $_SESSION['id'] = $id;
- echo 'Welcome ' . $_SESSION['name'] . '!';
- header('Location: https://x-sim.co.uk/home.php');
- } else {
- header('Location: https://x-sim.co.uk/loginfailed.html');
- }
- } else {
- header('Location: https://x-sim.co.uk/loginfailed.html');
- }
- $stmt->close();
- } else {
- echo 'Could not prepare statement!';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement