You are here: Re: Active directory and PHP « PHP Language « IT news, forums, messages
Re: Active directory and PHP

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация