php-windows Digest 14 Mar 2006 11:48:09 -0000 Issue 2909

Topics (messages 26749 through 26750):

Re: LDAP newb gets errors against 2003 AD
        26749 by: Aaron Kenney

include txt in html
        26750 by: Alf Stockton

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        php-windows@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
After making the recommended changes, the browser returned:

     LDAP bind successful...
     Warning: ldap_search() [function.ldap-search]: Search: Bad search
filter in
     e:\intertest\test.php on line 20

     Warning: ldap_get_entries(): supplied argument is not a valid
ldap result resource in
     e:\intertest\test.php on line 21

So my goal then is to produce a valid search filter.
I considered the most basic filter:

     $filter = "(cn=*)";

And got this back:

     LDAP bind successful...
     Warning: ldap_search() [function.ldap-search]: Search: Operations
error in
     e:\intertest\test.php on line 20

     Warning: ldap_get_entries(): supplied argument is not a valid
ldap result resource in
     e:\intertest\test.php on line 21

Did some googling and found that Win 2003 AD does not like the default
ldap settings for PHP. So I insert this code:

     if ($ldapconn)
     {
     ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION,3);
     ldap_set_option($ldapconn, LDAP_OPT_REFERRALS,0);
     $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

And got back an error of too many results or something like that. So I
narrowed the filter to:

     $filter = "(cn=*Kenney*)";

AND IT WORKS!
Also the field "ou" doesn't produce any results, so I did "sn"
instead, which returns the last name.
So for those who want the big picture (I usually do), here's what I
wound up with:

     <?PHP
     $ldaprdn = '[EMAIL PROTECTED]';
     $ldappass = 'PWD';
     $ds = 'servername.domainname.net';
     $dn = 'dc=domainname,dc=net';
     $ldapport = 389;
     $ldapconn = ldap_connect($ds, $ldapport)
     or die("Could not connect to LDAP server.");

     if ($ldapconn)
     {
     ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION,3);
     ldap_set_option($ldapconn, LDAP_OPT_REFERRALS,0);
     $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
     if ($ldapbind)
     {
     echo "LDAP bind successful...";

     $filter = "(cn=*Kenney*)";
     $fields = array("sn", "mail");
     $sr = ldap_search($ldapconn, $dn, $filter, $fields);
     $info = ldap_get_entries($ldapconn, $sr);

     for ($i=0; $i<$info["count"]; $i++)
     {
     echo "<br>";
     echo "lastname: " . $info[$i]["sn"][0];
     echo "<br>";
     echo "mail: " . $info[$i]["mail"][0];
     }
     }
     else
     {
     echo "LDAP bind failed...";
     }
     }
     ldap_close($ldapconn);
     ?>

-Aaron Kenney


On 3/9/06, Bowden, Zeb <[EMAIL PROTECTED]> wrote:
> The first parameter of ldap_search is the link resource (i.e.
> $ldapconn).
> I think something like this should work:
>
>         $sr = ldap_search($ldapconn, $dn, $filter, $fields);
>         $info = ldap_get_entries($ldapconn, $sr);
>
> -zeb
>
>
>
> -----Original Message-----
> From: Aaron Kenney [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 08, 2006 5:30 PM
> To: php-windows@lists.php.net
> Subject: [PHP-WIN] LDAP newb gets errors against 2003 AD
>
> So here is the offending code:
>
> --------------------------------------------------
> <?PHP
> $ldaprdn = '[EMAIL PROTECTED]';
> $ldappass = 'PWD';
> $ds = 'server.domain.net';
> $dn = 'dc=domain,dc=net';
> $ldapport = 389;
> $ldapconn = ldap_connect($ds, $ldapport)
> or die("Could not connect to LDAP server.");
>
> if ($ldapconn)
> {
> $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
> if ($ldapbind)
> {
> echo "LDAP bind successful...";
>
>
> $filter = "'cn=*Kenney*'";
> $fields = array("ou", "mail");
> $sr = ldap_search($ds, $dn, $filter, $fields);
>
> $info = ldap_get_entries($ds, $sr);
>
> for ($i=0; $i<$info["count"]; $i++)
> {
> echo "<br>";
> echo "ou: " . $info[$i]["ou"][0];
> echo "mail: " . $info[$i]["mail"][0];
> }
>
> }
> else
> {
> echo "LDAP bind failed...";
> }
> }
> ldap_close($ldapconn);
> ?>
> ----------------------------------------------
>
> Here is the result:
> -------------------------------------
> LDAP bind successful...
> Warning: ldap_search(): supplied argument is not a valid ldap link
> resource in e:\intertest\test.php on line 20
>
> Warning: ldap_get_entries(): supplied argument is not a valid ldap
> link resource in e:\intertest\test.php on line 22
> ------------------------------------------
>
> I know I'm just misusing the ldap_search() function or something, so
> please, someone set me straight here.
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message --- From what I have read on the web I am given to understand that I can include text files in a html document by issuing the following in the html file
<!--#include file="Registration.txt"-->
This however does not work for me.
My 1st thought was that I had not allowed for SSIs in my httpd.conf but my httpd.conf Options is as follows
Options Indexes Includes FollowSymLinks MultiViews ExecCGI
So if someone can share with me how I got this wrong I would be grateful.

--
Regards,
Alf Stockton            www.stockton.co.za

"Life, loathe it or ignore it, you can't like it."
                -- Marvin, "Hitchhiker's Guide to the Galaxy"

My email disclaimer is available at www.stockton.co.za/disclaimer.html

--- End Message ---

Reply via email to