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>
13 protected $ldap = Null;
22 * Constructs a new instance of LDAP class.
24 public function __construct () {
25 if (!extension_loaded("ldap")) {
26 throw new Exception("Can not find LDAP extension.");
31 * connect to a ldap server
33 * @param string $server
34 * @param integer $port
36 * @return bool true/false
38 public function connect ($server, $port, $dn) {
39 $this->ldap
= ldap_connect($server, $port);
43 ldap_set_option($this->ldap
, LDAP_OPT_PROTOCOL_VERSION
, 3);
44 ldap_set_option($this->ldap
, LDAP_OPT_REFERRALS
, 0);
48 throw new Exception("Cant connect to ldap server.");
55 * returns ldap user array
58 * @param string $password
61 public function bind ($user, $password) {
62 return ldap_bind($this->ldap
, $user.",".$this->dn
, $password);
66 * search user on ldap server
68 * @param string $search
71 public function search ($search) {
72 return ldap_search($this->ldap
, $this->dn
, $search);
76 * get entries from search resource
78 * @param resource $resource
81 public function get_entries ($resource) {
82 return ldap_get_entries($this->ldap
, $resource);
86 * close ldap connection
88 public function close () {
89 ldap_close($this->ldap
);