📄 function.ldap-connect.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Connect to an LDAP server</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.ldap-compare.html">ldap_compare</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.ldap-count-entries.html">ldap_count_entries</a></div> <div class="up"><a href="ref.ldap.html">LDAP Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.ldap-connect" class="refentry"> <div class="refnamediv"> <h1 class="refname">ldap_connect</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">ldap_connect</span> — <span class="dc-title">Connect to an LDAP server</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><b><b>ldap_connect</b></b></span> ([ <span class="methodparam"><span class="type">string</span> <tt class="parameter">$hostname</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$port</tt></span> ]] )</div> <p class="para rdfs-comment"> Establishes a connection to a LDAP server on a specified <i><tt class="parameter">hostname</tt></i> and <i><tt class="parameter">port</tt></i>. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">hostname</tt></i></span> <dd> <p class="para"> If you are using OpenLDAP 2.x.x you can specify a URL instead of the hostname. To use LDAP with SSL, compile OpenLDAP 2.x.x with SSL support, configure PHP with SSL, and set this parameter as <i>ldaps://hostname/</i>. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">port</tt></i></span> <dd> <p class="para"> The port to connect to. Not used when using URLs. Defaults to 389. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a positive LDAP link identifier on success, or <b><tt>FALSE</tt></b> on error. When OpenLDAP 2.x.x is used, <b>ldap_connect()</b> will always return a <a href="language.types.resource.html" class="type resource">resource</a> as it does not actually connect but just initializes the connecting parameters. The actual connect happens with the next calls to ldap_* funcs, usually with <a href="function.ldap-bind.html" class="function">ldap_bind()</a>. </p> <p class="para"> If no arguments are specified then the link identifier of the already opened link will be returned. </p> </div> <div class="refsect1 changelog"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">4.0.4</td> <td colspan="1" rowspan="1" align="left"> URL and SSL support was added. </td> </tr> </tbody> </colgroup> </table> </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Example of connecting to LDAP server.</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">// LDAP variables<br /></span><span style="color: #0000BB">$ldaphost </span><span style="color: #007700">= </span><span style="color: #DD0000">"ldap.example.com"</span><span style="color: #007700">; </span><span style="color: #FF8000">// your ldap servers<br /></span><span style="color: #0000BB">$ldapport </span><span style="color: #007700">= </span><span style="color: #0000BB">389</span><span style="color: #007700">; </span><span style="color: #FF8000">// your ldap server's port number<br /><br />// Connecting to LDAP<br /></span><span style="color: #0000BB">$ldapconn </span><span style="color: #007700">= </span><span style="color: #0000BB">ldap_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$ldaphost</span><span style="color: #007700">, </span><span style="color: #0000BB">$ldapport</span><span style="color: #007700">)<br /> or die(</span><span style="color: #DD0000">"Could not connect to $ldaphost"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> <div class="example"> <p><b>Example #2 Example of connecting securely to LDAP server.</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">// make sure your host is the correct one<br />// that you issued your secure certificate to<br /></span><span style="color: #0000BB">$ldaphost </span><span style="color: #007700">= </span><span style="color: #DD0000">"ldaps://ldap.example.com/"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Connecting to LDAP<br /></span><span style="color: #0000BB">$ldapconn </span><span style="color: #007700">= </span><span style="color: #0000BB">ldap_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$ldaphost</span><span style="color: #007700">)<br /> or die(</span><span style="color: #DD0000">"Could not connect to {$ldaphost}"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.ldap-bind.html" class="function" rel="rdfs-seeAlso">ldap_bind()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.ldap-compare.html">ldap_compare</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.ldap-count-entries.html">ldap_count_entries</a></div> <div class="up"><a href="ref.ldap.html">LDAP Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -