LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-08-2006, 12:38 PM   #1
ckoniecny
Member
 
Registered: Oct 2005
Posts: 162

Rep: Reputation: 30
LDAP Queries with PHP


I'm trying to extract information from our OpenLDAP server. I am able to extract the "cn", "street", "st" and "mail". I also want to extract the "postalCode" and "telephoneNumber", but I am unable to. Here is my code:

PHP Code:
<?php
if (($ldap_con ldap_connect("server.domain.com")) != false)
{
        
ldap_set_option($ldap_conLDAP_OPT_PROTOCOL_VERSION3);

        if (
ldap_bind($ldap_con'uid=ldapuser,cn=users,dc=server,dc=domain,dc=com''password'))
        {
                
$ldap_usr ldap_search($ldap_con'dc=server,dc=domain,dc=com'"(uid=*)");

                if (
$ldap_usr != false)
                {
                        
$ldap_user_data ldap_get_entries($ldap_con$ldap_usr);
                        for ( 
$i $i $ldap_user_data["count"] ; $i++ )
                        {
                                echo 
"Name: ".$ldap_user_data[$i]["cn"][0] . "<br>";
                                echo 
"Email Address: ".$ldap_user_data[$i]["mail"][0]."<br>";
                                echo 
"Street: ".$ldap_user_data[$i]["street"][0]."<br>";
                                echo 
"City: ".$ldap_user_data[$i]["l"][0]." State: ".$ldap_user_data[$i]["st"][0]." Zip Code: ".$ldap_user_data[$i]["postalCode"][0]."<br>";
                                echo 
"Telephone Number: ".$ldap_user_data[$i]["telephoneNumber"][0]."<br>";
                        }
                }
                else
                {
                        echo 
"ldap_search failed";
                }
        }
}
else
{
        echo 
"ldap_bind failed with".ldap_error($ldap_con);
}
ldap_unbind($ldap_conn);
?>
My results look like:

Code:
Name: Jane Doe
Email Address: jdoe@domain.com
Street: 123 Street St.
City: Anywhere State: MI Zip Code: 
Telephone Number:
As you can see, I am unable to extract data into the Telephone Number and Zip Code fields. If I use an LDAP browser to look at the LDAP server I see that information exists in those fields, but I cant extract it for some reason. Any ideas?
 
Old 03-08-2006, 05:34 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by ckoniecny
I also want to extract the "postalCode" and "telephoneNumber", but I am unable to. Here is my code:
PHP Code:
<?php
// ..snip..
echo "Telephone Number: ".$ldap_user_data[$i]["telephoneNumber"][0]."<br>";
// ..snip..
?>
The manual says: "The attribute index is converted to lowercase." (a bit unexpected behaviour, I agree). So just changing ["telephoneNumber"][0]" to ["telephonenumber"][0]" will fix your problem.

Last edited by Hko; 03-08-2006 at 06:49 PM.
 
Old 03-08-2006, 06:58 PM   #3
ckoniecny
Member
 
Registered: Oct 2005
Posts: 162

Original Poster
Rep: Reputation: 30
Thank you, thats what the problem was.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php + ldap berrance General 4 08-17-2005 05:57 AM
Security risks of php based mysql queries TigerOC Linux - Security 5 04-10-2005 07:30 AM
SQL queries per page (PHP, MySQL) Silent1 Programming 2 06-27-2004 11:15 PM
php post data sql queries... bulliver Programming 2 01-03-2003 02:18 AM
PHP Script to retrieve queries from log file saravanan1979 Programming 1 03-17-2002 08:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration