|
Posted by ZeldorBlat on 09/26/22 12:01
On Jan 28, 1:01 pm, "mlimacar...@gmail.com" <mlimacar...@gmail.com>
wrote:
> Is there anyway to work PHP with Active directory? My intention
> consist in developing an application that authenticates automatically
> PHP on W2k3 server.
> tks,
> Marcos
Here's how I usually do it. Requires the PHP LDAP extension:
$domain_controller = 'mydc';
$domain = 'foo.local';
if(empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW']))
{
header('WWW-Authenticate: Basic realm="' . $domain . '"');
header('HTTP/1.0 401 Unauthorized');
die(); //if they hit cancel
}
if(($ldap = @ldap_connect($domain_controller, 389)) !== false) {
if(@ldap_bind($ldap, $_SERVER['PHP_AUTH_USER'] . '@' . $domain,
$_SERVER['PHP_AUTH_PW']) !== false) {
//Their credentials were valid, so do whatever you need to do
}
else {
//Their credentials weren't valid
header('WWW-Authenticate: Basic realm="' . $domain . '"');
header('HTTP/1.0 401 Unauthorized');
die(); //if they hit cancel
}
}
Navigation:
[Reply to this message]
|