<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.ldap.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.ldap-connect.php',
    1 => 'ldap_connect',
    2 => 'Connect to an LDAP server',
  ),
  'up' => 
  array (
    0 => 'ref.ldap.php',
    1 => 'LDAP Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.ldap-compare.php',
    1 => 'ldap_compare',
  ),
  'next' => 
  array (
    0 => 'function.ldap-connect-wallet.php',
    1 => 'ldap_connect_wallet',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/ldap/functions/ldap-connect.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.ldap-connect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ldap_connect</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ldap_connect</span> &mdash; <span class="dc-title">Connect to an LDAP server</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.ldap-connect-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ldap_connect</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$uri</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><span class="type"><a href="class.ldap-connection.php" class="type LDAP\Connection">LDAP\Connection</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <div class="warning"><strong class="warning">Avviso</strong>
   <p class="simpara">
    As of PHP 8.3.0, the <em>following</em> signature is deprecated.
   </p>
  </div>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ldap_connect</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$host</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$port</code><span class="initializer"> = 389</span></span>): <span class="type"><span class="type"><a href="class.ldap-connection.php" class="type LDAP\Connection">LDAP\Connection</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Creates an <span class="classname"><a href="class.ldap-connection.php" class="classname">LDAP\Connection</a></span> connection and checks whether the given
   <code class="parameter">uri</code> is plausible.
  </p>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <span class="simpara">
    This function does <em>not</em> open a connection.
    It checks whether the given parameters are plausible and can be used
    to open a connection as soon as one is needed.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ldap-connect-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">uri</code></dt>
     <dd>
      <p class="para">
       A full LDAP URI of the form <code class="literal">ldap://hostname:port</code>
       or <code class="literal">ldaps://hostname:port</code> for SSL encryption.
      </p>
      <p class="para">
       You can also provide multiple LDAP-URIs separated by a space as one string
      </p>
      <p class="para">
       Note that <code class="literal">hostname:port</code> is not a supported LDAP URI as the schema is missing.
      </p>
     </dd>
    
    
     <dt><code class="parameter">host</code></dt>
     <dd>
      <p class="para">
       The hostname to connect to.
      </p>
     </dd>
    
    
     <dt><code class="parameter">port</code></dt>
     <dd>
      <p class="para">
       The port to connect to.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ldap-connect-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Returns an <span class="classname"><a href="class.ldap-connection.php" class="classname">LDAP\Connection</a></span> instance when the provided LDAP URI
   seems plausible. It&#039;s a syntactic check of the provided parameter but the server(s) will not
   be contacted! If the syntactic check fails it returns <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
   <span class="function"><strong>ldap_connect()</strong></span> will otherwise
   return a <span class="classname"><a href="class.ldap-connection.php" class="classname">LDAP\Connection</a></span> instance as it does not actually connect but just
   initializes the connecting parameters.  The actual connect happens with
   the next calls to ldap_* functions, usually with
   <span class="function"><a href="function.ldap-bind.php" class="function">ldap_bind()</a></span>.
  </p>
  <p class="para">
   If no argument is specified then the <span class="classname"><a href="class.ldap-connection.php" class="classname">LDAP\Connection</a></span> instance of the already
   opened connection will be returned.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.ldap-connect-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versione</th>
      <th>Descrizione</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       Calling <span class="function"><strong>ldap_connect()</strong></span> with separate
       <code class="parameter">hostname</code> and <code class="parameter">port</code>
       is now deprecated.
      </td>
     </tr>

     <tr>
      <td>8.1.0</td>
      <td>
       Returns an <span class="classname"><a href="class.ldap-connection.php" class="classname">LDAP\Connection</a></span> instance now;
       previously, a <a href="language.types.resource.php" class="link">resource</a> was returned.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.ldap-connect-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Example of connecting to LDAP server.</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// LDAP variables<br /></span><span style="color: #0000BB">$ldapuri </span><span style="color: #007700">= </span><span style="color: #DD0000">"ldap://ldap.example.com:389"</span><span style="color: #007700">;  </span><span style="color: #FF8000">// your ldap-uri<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">$ldapuri</span><span style="color: #007700">)<br />          or die(</span><span style="color: #DD0000">"That LDAP-URI was not parseable"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
   <div class="example" id="example-2">
    <p><strong>Example #2 Example of connecting securely to LDAP server.</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?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">"That LDAP-URI was not parseable"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ldap-connect-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.ldap-bind.php" class="function" rel="rdfs-seeAlso">ldap_bind()</a> - Bind to LDAP directory</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>