You can create a clean LDAP PHP server with this library (I wrote it originally for the purposes of the LDAP client):
https://github.com/FreeDSx/LDAP
It works based on a request handler (interface only) for client requests. Basically, you extend a class that will handle client requests and send a response back (in the case of a search anyway). Basic example:
- Create a request handler that extends the general request handler in the library:
namespace Foo; use FreeDSx\Ldap\Server\RequestHandler\GenericRequestHandler; class LdapRequestHandler extends GenericRequestHandler { protected $users = [ 'user' => '12345', ]; public function bind(string $username, string $password): bool { return isset($this->users[$username]) && $this->users[$username] === $password; } public function search(RequestContext $context, SearchRequest $search): Entries {
- Using the request handler, create an LDAP server process that listens on port 389 for clients:
use FreeDSx\Ldap\LdapServer; use Foo\LdapRequestHandler; $server = new LdapServer([ 'request_handler' => LdapRequestHandler::class ]); $server->run();
There are more documents here on the server component of the library:
https://github.com/FreeDSx/LDAP/tree/master/docs/Server
A few caveats:
- Currently paging / vlv server support for server
- There is currently no way to return controls from the request handler back to the client.
source share