Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //login.php
- /**
- * Start the session.
- */
- session_start();
- /**
- * Include our MySQL connection.
- */
- require 'connect.php';
- //If the POST var "login" exists (our submit button), then we can
- //assume that the user has submitted the login form.
- if(isset($_POST['submit'])){
- //Retrieve the field values from our login form.
- $username = !empty($_POST['username']) ? trim($_POST['username']) : null;
- $passwordAttempt = !empty($_POST['password']) ? trim($_POST['password']) : null;
- //Retrieve the user account information for the given username.
- $sql = "SELECT username, password FROM l_pelanggan WHERE username = :username";
- $stmt = $pdo->prepare($sql);
- var_dump($stmt);
- //Bind value.
- $stmt->bindValue(':username', $username);
- //Execute.
- $stmt->execute();
- //Fetch row.
- $user = $stmt->fetch(PDO::FETCH_ASSOC);
- //If $row is FALSE.
- if($user === false){
- //Could not find a user with that username!
- //PS: You might want to handle this error in a more user-friendly manner!
- echo "<script>window.alert('ID atau Password Salah')</script>";
- } else{
- //User account found. Check to see if the given password matches the
- //password hash that we stored in our users table.
- //Compare the passwords.
- $validPassword = password_verify($passwordAttempt, $user['password']);
- //If $validPassword is TRUE, the login has been successful.
- if($validPassword){
- //Provide the user with a login session.
- $_SESSION['username'] = $username;
- //Redirect to our protected page, which we called home.php
- header('Location: index_list.php?id='.$user['id_pelanggan'].'');
- exit;
- } else{
- //$validPassword was FALSE. Passwords do not match.
- echo "<script>window.alert('ID atau Password Salah')</script>";
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement