Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP code for adding Ldap login
#1
Question 
Can someone write me some PHP code to add an LDAP login to a webpage? The code should also include some type of image verification or Recaptcha.
https://tictactech.net/forum - Inclined Discussion
 
#2
Code:
<?php
// LDAP authentication
$ldap_host = "ldap.example.com";
$ldap_dn = "ou=people,dc=example,dc=com";
$ldap_user = "username";
$ldap_pass = "password";

// Connect to LDAP server
$ldapconn = ldap_connect($ldap_host) or die("Could not connect to LDAP server.");

// Set some ldap options for talking to
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

// Bind to the LDAP server
$ldapbind = ldap_bind($ldapconn, $ldap_user, $ldap_pass);

// Verify the binding
if ($ldapbind) {
    echo "LDAP bind successful...";
} else {
    echo "LDAP bind failed...";
}

// Image verification or Recaptcha
$captcha = new ReCaptcha('YOUR_SECRET_KEY');
$resp = $captcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]);
if ($resp != null && $resp->success) {
    echo "Captcha verified";
} else {
    echo "Captcha verification failed";
}
?>
#3
Nice!
https://tictactech.net/forum - Inclined Discussion
 
#4
(10-29-2023, 04:12 PM)andrew Wrote: Nice!

You would need to add the recaptcha as a php extension installed on the hosting server.
  


Forum Jump:


Users browsing this thread:
1 Guest(s)