Guest User

Untitled

a guest
Sep 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. <?php
  2. ob_start();
  3. session_start();
  4.  
  5. //set timezone
  6. date_default_timezone_set('Europe/London');
  7.  
  8. //database credentials
  9. define('DBHOST','XXXX');
  10. define('DBUSER','XXXX');
  11. define('DBPASS','XXXX');
  12. define('DBNAME','XXXX');
  13.  
  14. //application address
  15. define('DIR','XXXX');
  16. define('SITEEMAIL','XXXX');
  17.  
  18. try {
  19.  
  20. //create PDO connection
  21. $db = new PDO("mysql:host=".DBHOST.";charset=utf8mb4;dbname=".DBNAME, DBUSER, DBPASS);
  22. //$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);//Suggested to uncomment on production websites
  23. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);//Suggested to comment on production websites
  24. $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  25.  
  26. } catch(PDOException $e) {
  27. //show error
  28. echo '<p class="bg-danger">'.$e->getMessage().'</p>';
  29. exit;
  30. }
  31.  
  32. //include the user class, pass in the database connection
  33. include('classes/user.php');
  34. include('classes/phpmailer/mail.php');
  35. $user = new User($db);
  36. ?>
  37.  
  38. <?php
  39. //include config
  40. require_once('includes/config.php');
  41.  
  42. //check if already logged in move to home page
  43. if( $user->is_logged_in() ){ header('Location: index.php'); exit(); }
  44.  
  45. //process login form if submitted
  46. if(isset($_POST['submit'])){
  47.  
  48. if (!isset($_POST['username'])) $error[] = "Please fill out all fields";
  49. if (!isset($_POST['password'])) $error[] = "Please fill out all fields";
  50.  
  51. $username = $_POST['username'];
  52.  
  53. if (!isset($_POST['password'])){
  54. $error[] = 'A password must be entered';
  55. }
  56. $password = $_POST['password'];
  57.  
  58. if($user->login($username,$password)){
  59. $_SESSION['username'] = $username;
  60. header('Location: memberpage.php');
  61. exit;
  62.  
  63. } else {
  64. $error[] = 'Wrong username or password or your account has not been activated.';
  65. }
  66. }
  67.  
  68.  
  69.  
  70. $title = 'Login';
  71. require('layout/header.php');
  72. ?>
Add Comment
Please, Sign In to add comment