php-doc-en/reference/ldap/functions/ldap-connect.xml
2016-01-30 12:57:21 +00:00

149 lines
4.2 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.ldap-connect" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>ldap_connect</refname>
<refpurpose>Connect to an LDAP server</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>resource</type><methodname>ldap_connect</methodname>
<methodparam choice="opt"><type>string</type><parameter>host</parameter><initializer>&null;</initializer></methodparam>
<methodparam choice="opt"><type>int</type><parameter>port</parameter><initializer>389</initializer></methodparam>
</methodsynopsis>
<para>
Creates an LDAP link identifier and checks whether the given
<parameter>host</parameter> and <parameter>port</parameter> are plausible.
</para>
<para>
Note: This function does <emphasis>not</emphasis> open a connection.
It checks whether the given parameters are plausibe and can be used
to open a connection as soon as one is needed.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>host</parameter></term>
<listitem>
<para>
This field supports using a hostname or, with OpenLDAP 2.x.x and
later, a full LDAP URI of the form <literal>ldap://hostname:port</literal>
or <literal>ldaps://hostname:port</literal> for SSL encryption.
</para>
<para>
You can also provide multiple LDAP-URIs separated by a space as one string
</para>
<para>
Note that <literal>hostname:port</literal> is not a supported LDAP URI as the schema is missing.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>port</parameter></term>
<listitem>
<para>
The port to connect to. Not used when using LDAP URIs.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a positive LDAP link identifier when the provided hostname/port combination or LDAP URI
seems plausible. It's a syntactic check of the provided parameters but the server(s) will not
be contacted! If the syntactic check fails it returns &false;.
When OpenLDAP 2.x.x is used, <function>ldap_connect</function> will always
return a <type>resource</type> 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
<function>ldap_bind</function>.
</para>
<para>
If no arguments are specified then the link identifier of the already
opened link will be returned.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Example of connecting to LDAP server.</title>
<programlisting role="php">
<![CDATA[
<?php
// LDAP variables
$ldaphost = "ldap.example.com"; // your ldap servers
$ldapport = 389; // your ldap server's port number
// Connecting to LDAP
$ldapconn = ldap_connect($ldaphost, $ldapport)
or die("Could not connect to $ldaphost");
?>
]]>
</programlisting>
</example>
<example>
<title>Example of connecting securely to LDAP server.</title>
<programlisting role="php">
<![CDATA[
<?php
// make sure your host is the correct one
// that you issued your secure certificate to
$ldaphost = "ldaps://ldap.example.com/";
// Connecting to LDAP
$ldapconn = ldap_connect($ldaphost)
or die("Could not connect to {$ldaphost}");
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>ldap_bind</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->