Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


A Sample LDAP Application in PHP Page 21

February 22, 2002

We collect the attributes of the new entry to be added in an associative array:

        $entryToAdd["cn"] = $cn;
        $entryToAdd["sn"] = $sn;
        $entryToAdd["mail"] = $mail;
        $entryToAdd["employeenumber"] = $employeenumber;
        $entryToAdd["ou"] = $ou;
        $entryToAdd["telephonenumber"] = $telephonenumber;
        $entryToAdd["objectclass"] = "person";
        $entryToAdd["objectclass"] = "organizationalPerson";
        $entryToAdd["objectclass"] = "inetOrgPerson";

Here we construct the DN corresponding to the new entry:

        $dnString = "mail=" . $mail . "," . "ou=". $ou . "," . $baseDN;

This is the root DN we shall bind to, before performing the add operation:

        $adminRDN = "cn=Admin," . $baseDN;

We connect to the server and bind as an administrator:

        $linkIdentifier = connectBindServer($adminRDN, $adminpassword);
        if ($linkIdentifier) {

The actual addition is done here:

            if (ldap_add($linkIdentifier, $dnString,
			 $entryToAdd) == true) {
                generateHTMLHeader("The entry was added succesfully");
                returnToMain();
            } else {
                displayErrMsg("Addition to directory failed ! !");
                closeConnection($linkIdentifier);
                returnToMain();
                exit;
            }
        } else {
            displayErrMsg("Connection to LDAP server failed!");
            exit;
        }
    }
}
?>

[The red lines above are one line. They have been split for formatting purposes.]

[In the code above, there should be no space between the double "!" marks. They have been separated for formatting purposes.]

A typical screen prompting the user to enter the attributes would like below:

We need to be aware of certain caveats with this application that arise from the fact that this is merely illustrative of the PHP LDAP API and not a fully-fledged production application. As mentioned before the use of HTTP sessions is highly recommended to indicate authentication status. Further users created using the add mechanism do not have a password field due to which modification of such entries is not possible through the current mechanism.

A Sample LDAP Application in PHP Page 20
Professional PHP4 Programming
A Sample LDAP Application in PHP Page 22


Up to => Home / Authoring / Languages / PHP / Pro




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers