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.");
30 * connect to a ldap server
32 * @param string $server
33 * @param integer $port
35 * @return bool true/false
37 public function connect ($server, $port, $dn) {
38 $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);
45 throw new Exception("Cant connect to ldap server.");
51 * returns ldap user array
54 * @param string $password
57 public function bind ($user, $password) {
58 return ldap_bind($this->ldap
, $user.",".$this->dn
, $password);
62 * search user on ldap server
64 * @param string $search
67 public function search ($search) {
68 return ldap_search($this->ldap
, $this->dn
, $search);
72 * get entries from search resource
74 * @param resource $resource
77 public function get_entries ($resource) {
78 return ldap_get_entries($this->ldap
, $resource);
82 * close ldap connection
84 public function close () {
85 ldap_close($this->ldap
);