Advertisement
Guest User

Untitled

a guest
Jul 18th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: putuguna
  5. * Date: 7/18/2016
  6. * Time: 8:09 AM
  7. */
  8. require_once ("../connection/ConnectionDB.php");
  9. class Login {
  10. function loginToYourDashboard(){
  11. $connection = new ConnectionDB();
  12. $conn = $connection->getConnection();
  13. try{
  14. if(isset($_POST['submit'])){
  15. if(empty($_POST['username']) || empty($_POST['password'])){
  16. header('Location: UsernamePasswordWrong.php');
  17. }else{
  18. $username = $_POST['username'];
  19. $password = $_POST['password'];
  20. $sql = "SELECT * FROM login";
  21. $result = $conn->prepare($sql);
  22. $result->execute();
  23. foreach($result as $data){
  24. if($username!=$data['username']){
  25. header('Location: UsernamePasswordWrong.php');
  26. }else if($password!=$data['password']){
  27. header('Location: UsernamePasswordWrong.php');
  28. }else{
  29. session_start(); // turn the session on
  30. $_SESSION['username'] = $username; // use username as the session
  31. header('Location: FormLogin.php');
  32. }
  33. }
  34. }
  35. }
  36. }catch (PDOException $e){
  37. echo "ERROR : " . $e->getMessage();
  38. }
  39. }
  40. }
  41. $login = new Login();
  42. $login->loginToYourDashboard();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement