note 125082 added to function.ldap-bind
| From: | peter dot mlich at volny dot cz | Date: | Fri, 05 Jun 2020 07:07:32 +0000 |
| Subject: | note 125082 added to function.ldap-bind | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214723@lists.php.net to get a copy of this message | ||
Example code from my ldap class.
this->query i send notes under ldap_search function documentation.
public function queryUserLogin($user_name='', $user_psw='', $tls_bool=true) //
na localhostu pouzit tls=false
{
var_dump('queryUserLogin');
//$tls_bool = false; // for localhost
$fn = 'queryUser';
$config = $this->config;
$conn = $this->conn;
if (!$conn)
{return $this->errorConnection($fn);}
// user - exist name?
$user_name = $this->escapeValue($user_name);
$user_psw = $this->escapeValue($user_psw);
$filter = "(&(objectclass=person)(cn=".$user_name."))";
//var_dump($filter);
$att = array('dn');
$data = $this->query($filter, $att, 2, true);
if ($data===false)
{
$this->error("User error, nenalezen v ldap!");
$this->disconnect();
return false;
}
// user - exist user in LDAP (name, psw)
$user = is_array($data) && isset($data[0]) && isset($data[0]['dn']) ?
$data[0]['dn'] : ''; // "cn=mynickname,ou=users,o=su"
$psw = $user_psw;
if ($user=='' || $psw=='')
{
$this->error("User error, prazdne prihlasovaci udaje!");
$this->disconnect();
return false;
}
if ($tls_bool==true)
{
if (ldap_start_tls($conn)) //php7
{
$result = @ldap_bind($conn, $user, $psw);
}
else {
$this->error("Unable to start TLS!"); // SSL encrypt protocol, certificate,
deprecated?
}
}
else {
$result = @ldap_bind($conn, $user, $psw);
}
if ($result==false)
{
$this->error("Bind user error! bindDN = ".$user); //".ldap_error($conn)."
$this->disconnect();
return false;
}
// user - get user info, bind to ldap user with more permitions and get data (login to intercon
user)
$user = $config['userInterconDn'];
$psw = $config['userInterconPsw'];
if ($tls_bool==true)
{
if (ldap_start_tls($conn)) //php7
{
$result = ldap_bind($conn, $user, $psw);
}
else {
$this->error("Unable to start TLS!"); // SSL encrypt protocol, certificate,
deprecated?
}
}
else {
$result = ldap_bind($conn, $user, $psw);
}
if ($result==false)
{
$this->error("Bind user intercon error!"); // . ldap_error($conn) !Nezobrazovat jmeno
usera interconu
$this->out = array(
'uid' => $user
);
return true;
}
// search user data
$filter = "(&(objectclass=person)(cn=" . $user_name . "))";
//var_dump($filter);
$att = array(
'uid',
'workforceID',
'employeeID',
'givenName',
'sn',
'mail'
);
$data = $this->query($filter, $att, 2, true);
// get data from ldap entires structure
$this->out = array(
'uid' => $this->dataGetValue($data, 'uid' ,
''),
'workforceID' => $this->dataGetValue($data, 'workforceid',
''),
'employeeID' => $this->dataGetValue($data, 'employeeid' ,
''),
'givenName' => $this->dataGetValue($data, 'givenname' ,
''),
'sn' => $this->dataGetValue($data, 'sn' ,
''), // prijmeni
'mail' => $this->dataGetValue($data, 'mail' ,
'') // mail
);
$this->conn = $conn;
return true;
}
----
Server IP: 45.112.84.4
Probable Submitter: 103.51.167.36 (proxied: 2001:718:2601:258:4dbc:3838:5a25:f2e0)
----
Manual Page -- http://php.net/manual/en/function.ldap-bind.php
Edit -- https://master.php.net/note/edit/125082
Del: integrated -- https://master.php.net/note/delete/125082/integrated
Del: useless -- https://master.php.net/note/delete/125082/useless
Del: bad code -- https://master.php.net/note/delete/125082/bad+code
Del: spam -- https://master.php.net/note/delete/125082/spam
Del: non-english -- https://master.php.net/note/delete/125082/non-english
Del: in docs -- https://master.php.net/note/delete/125082/in+docs
Del: other reasons-- https://master.php.net/note/delete/125082
Reject -- https://master.php.net/note/reject/125082
Search -- https://master.php.net/manage/user-notes.php