3 * @author Jan Altensen (Stricted)
4 * @copyright 2013-2014 Jan Altensen (Stricted)
5 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
12 protected $ldap = Null;
20 * Constructs a new instance of LDAP class.
22 public function __construct () {
23 if (!extension_loaded("ldap")) {
24 throw new Exception("Can not find LDAP extension.");
29 * connect to a ldap server
31 * @param string $server
32 * @param integer $port
34 * @return bool true/false
36 public function connect ($server, $port, $dn) {
37 $this->ldap
= ldap_connect($server, $port);
41 ldap_set_option($this->ldap
, LDAP_OPT_PROTOCOL_VERSION
, 3);
42 ldap_set_option($this->ldap
, LDAP_OPT_REFERRALS
, 0);
46 throw new Exception("Cant connect to ldap server.");
53 * returns ldap user array
56 * @param string $password
59 public function bind ($user, $password) {
60 return ldap_bind($this->ldap
, $user.",".$this->dn
, $password);
64 * search user on ldap server
66 * @param string $search
69 public function search ($search) {
70 return ldap_search($this->ldap
, $this->dn
, $search);
74 * get entries from search resource
76 * @param resource $resource
79 public function get_entries ($resource) {
80 return ldap_get_entries($this->ldap
, $resource);
84 * close ldap connection
86 public function close () {
87 ldap_close($this->ldap
);