Find knowledge base article(s) by searching for keywords in the title e.g. type linux in the search box below
Find knowledge base article(s) by browsing the subject categories of articles
Technology quick references, cheatsheets, user manuals etc.
Shop Online through ShopifyLite
Tutorials on various IT applications.
Search Title    (UL:0 |SS:f)

Web >> Development >> PHP >> Simple example for LDAP authentication

/** {{{ http://code.activestate.com/recipes/101525/ (r1) */ <?php $ldapconfig['host'] = 'localhost'; $ldapconfig['port'] = NULL; $ldapconfig['basedn'] = 'dc=localhost,dc=com'; $ldapconfig['authrealm'] = 'My Realm'; function ldap_authenticate() { global $ldapconfig; global $PHP_AUTH_USER; global $PHP_AUTH_PW; if ($PHP_AUTH_USER != "" && $PHP_AUTH_PW != "") { $ds=@ldap_connect($ldapconfig['host'],$ldapconfig['port']); $r = @ldap_search( $ds, $ldapconfig['basedn'], 'uid=' . $PHP_AUTH_USER); if ($r) { $result = @ldap_get_entries( $ds, $r); if ($result[0]) { if (@ldap_bind( $ds, $result[0]['dn'], $PHP_AUTH_PW) ) { return $result[0]; } } } } header('WWW-Authenticate: Basic realm="'.$ldapconfig['authrealm'].'"'); header('HTTP/1.0 401 Unauthorized'); return NULL; } if (($result = ldap_authenticate()) == NULL) { echo('Authorization Failed'); exit(0); } echo('Authorization success'); print_r($result); ?> /** end of http://code.activestate.com/recipes/101525/ }}} */
[ © 2008-2021 myfaqbase.com - A property of WPDC Consulting ]