1
0

auth.php 930 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. session_start();
  3. if ($_SERVER['REQUEST_METHOD'] != 'POST') {
  4. header('Location: signin.php');
  5. exit();
  6. }
  7. if (!isset($_POST['id'], $_POST['password'])) {
  8. header('Location: signin.php');
  9. exit();
  10. }
  11. $id = htmlspecialchars($_POST['id']);
  12. $ini = parse_ini_file('includes/config.ini');
  13. try {
  14. $ldapconn = ldap_connect($ini['hostname'], $ini['port']);
  15. ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
  16. ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
  17. } catch (Exception $e) {
  18. die ('ERROR: ' . $e->getMessage());
  19. }
  20. if ($ldapconn) {
  21. $ldapbind = @ldap_bind($ldapconn, "uid=" . ldap_escape($id) . ',' . $ini["basedn"], $_POST['password']);
  22. if ($ldapbind) {
  23. $_SESSION['user'] = $id;
  24. header('Location: home.php');
  25. exit();
  26. } else {
  27. $_SESSION['message'] = "Wrong username or password";
  28. header('Location: signin.php');
  29. exit();
  30. }
  31. }