<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >ldap_compare</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="LDAP Functions" HREF="ref.ldap.html"><LINK REL="PREVIOUS" TITLE="ldap_close" HREF="function.ldap-close.html"><LINK REL="NEXT" TITLE="ldap_connect" HREF="function.ldap-connect.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.ldap-close.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.ldap-connect.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.ldap-compare" ></A >ldap_compare</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN100601" ></A ><P > (PHP 4 >= 4.0.2, PHP 5)</P >ldap_compare -- Compare value of attribute found in entry specified with DN</DIV ><DIV CLASS="refsect1" ><A NAME="AEN100604" ></A ><H2 >Descrição</H2 >mixed <B CLASS="methodname" >ldap_compare</B > ( resource link_identifier, string dn, string attribute, string value )<BR ></BR ><P > Compare <CODE CLASS="parameter" >value</CODE > of <CODE CLASS="parameter" >attribute</CODE > with value of same attribute in an LDAP directory entry. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN100624" ></A ><H2 >Parâmetros</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >link_identifier</CODE ></DT ><DD ><P > An LDAP link identifier, returned by <A HREF="function.ldap-connect.html" ><B CLASS="function" >ldap_connect()</B ></A >. </P ></DD ><DT ><CODE CLASS="parameter" >dn</CODE ></DT ><DD ><P > The distinguished name of an LDAP entity. </P ></DD ><DT ><CODE CLASS="parameter" >attribute</CODE ></DT ><DD ><P > The attribute name. </P ></DD ><DT ><CODE CLASS="parameter" >value</CODE ></DT ><DD ><P > The compared value. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN100649" ></A ><H2 >Valores de retornado</H2 ><P > Returns <TT CLASS="constant" ><B >TRUE</B ></TT > if <CODE CLASS="parameter" >value</CODE > matches otherwise returns <TT CLASS="constant" ><B >FALSE</B ></TT >. Returns -1 on error. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN100655" ></A ><H2 >Exemplos</H2 ><P > The following example demonstrates how to check whether or not given password matches the one defined in DN specified entry. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN100659" ></A ><P ><B >Exemplo 1. Complete example of password check</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br />$ds</font><font color="#007700">=</font><font color="#0000BB">ldap_connect</font><font color="#007700">(</font><font color="#DD0000">"localhost"</font><font color="#007700">); </font><font color="#FF8000">// assuming the LDAP server is on this host<br /><br /></font><font color="#007700">if (</font><font color="#0000BB">$ds</font><font color="#007700">) {<br /><br /> </font><font color="#FF8000">// bind<br /> </font><font color="#007700">if (</font><font color="#0000BB">ldap_bind</font><font color="#007700">(</font><font color="#0000BB">$ds</font><font color="#007700">)) {<br /><br /> </font><font color="#FF8000">// prepare data<br /> </font><font color="#0000BB">$dn </font><font color="#007700">= </font><font color="#DD0000">"cn=Matti Meikku, ou=My Unit, o=My Company, c=FI"</font><font color="#007700">;<br /> </font><font color="#0000BB">$value </font><font color="#007700">= </font><font color="#DD0000">"secretpassword"</font><font color="#007700">;<br /> </font><font color="#0000BB">$attr </font><font color="#007700">= </font><font color="#DD0000">"password"</font><font color="#007700">;<br /><br /> </font><font color="#FF8000">// compare value<br /> </font><font color="#0000BB">$r</font><font color="#007700">=</font><font color="#0000BB">ldap_compare</font><font color="#007700">(</font><font color="#0000BB">$ds</font><font color="#007700">, </font><font color="#0000BB">$dn</font><font color="#007700">, </font><font color="#0000BB">$attr</font><font color="#007700">, </font><font color="#0000BB">$value</font><font color="#007700">);<br /><br /> if (</font><font color="#0000BB">$r </font><font color="#007700">=== -</font><font color="#0000BB">1</font><font color="#007700">) {<br /> echo </font><font color="#DD0000">"Error: " </font><font color="#007700">. </font><font color="#0000BB">ldap_error</font><font color="#007700">(</font><font color="#0000BB">$ds</font><font color="#007700">);<br /> } elseif (</font><font color="#0000BB">$r </font><font color="#007700">=== </font><font color="#0000BB">true</font><font color="#007700">) {<br /> echo </font><font color="#DD0000">"Password correct."</font><font color="#007700">;<br /> } elseif (</font><font color="#0000BB">$r </font><font color="#007700">=== </font><font color="#0000BB">false</font><font color="#007700">) {<br /> echo </font><font color="#DD0000">"Wrong guess! Password incorrect."</font><font color="#007700">;<br /> }<br /><br /> } else {<br /> echo </font><font color="#DD0000">"Unable to bind to LDAP server."</font><font color="#007700">;<br /> }<br /><br /> </font><font color="#0000BB">ldap_close</font><font color="#007700">(</font><font color="#0000BB">$ds</font><font color="#007700">);<br /><br />} else {<br /> echo </font><font color="#DD0000">"Unable to connect to LDAP server."</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN100662" ></A ><H2 >Notas</H2 ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Atenção</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > <B CLASS="function" >ldap_compare()</B > can NOT be used to compare BINARY values! </P ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.ldap-close.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.ldap-connect.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >ldap_close</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.ldap.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >ldap_connect</TD ></TR ></TABLE ></DIV ></BODY ></HTML >