[Phpwm] PHP and LDAP

Marc Gale marc.gale at sbc.ac.uk
Thu Sep 7 09:10:23 BST 2006


I write a lot of PHP<->LDAP code and the following method works well for me.

As with most database connection models, set yourself up a series of
connection variables:

$ldapuser="FULL DN OF USER";
$ldappass="USER'S PASSWORD";
$ldapserver="NAME OF LDAP SERVER";

Now try to connect to the LDAP tree:

$ldapconn=ldap_connect($ldapserver) or die("Could not connect to LDAP");

If that's worked, try binding as the user

$ldapbind=ldap_bind($ldapconn,$ldapuser,$ldappass) or die("Couldn't bind to
the LDAP");

If you just want an anonymous connection (read only access to certain parts
of the tree), then you can bind in the following way:

$ldapbind=ldap_bind($ldapconn) or die("Couldn't bind to the LDAP");

I hope that helps

Marc

Tony Whitmore wrote:

> I'm looking at making a PHP web application authenticate against an LDAP
> tree. I'll be developing with a Free Software test LDAP server, probably
> OpenLDAP because it's the only one I've heard of.
>
> I've looked a bit at the documentation for the ldap_* functions and the
> examples in the comments that follow, but I'm not 100% clear on what
> fields I need to query the LDAP server for - surely the passwords aren't
> stored / transmitted in plain text? Here's what I want to happen:
>
> 1) User enters their username/password in a login page.
> 2) Their details are checked against the LDAP directory.
> 3) If the username/password is invalid, they are rejected.
> 4) If the username/password are authenticated, then some session
> variables are set up and we're good to go.
>
> Relatively simple, I think. But can anyone recommend some good HOWTOs or
> similar on getting up and running with PHP and LDAP?
>
> TIA,
>
> Tony
>
> _______________________________________________
> Phpwm mailing list
> Phpwm at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/phpwm
> Wiki: http://wiki.phpwm.org
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the Phpwm mailing list