Scripting Blogs

So....just how many entries is under that LDAP Branch??

PHP LDAP Authentication

User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

 How to Authenticate A LDAP User with PHP Script


So, we have a request from a user to login to our zFlex Online LDAP server using php code.  Well we decided to put together a snippet of code that can be used to authenticate a guest user on our server using php code.  Here is the sample below:



// using ldap bind
$ldaprdn  'uid=guest1,ou=users,ou=guests,dc=zflexsoftware,dc=com';     // ldap rdn or dn  (we will use the full DN)

$ldappass 'guest1password';  // associated password for guest1

// connect to ldap server
$ldapconn ldap_connect("")
    or die(
"Could not connect to zFlex LDAP server.");

if (
$ldapconn) {

// binding to zflex ldap server
$ldapbind ldap_bind($ldapconn$ldaprdn$ldappass);

    if (ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3)) {

            echo "\nUsing LDAPv3\n";

            echo "----------------";

            echo "\n";




        echo "Failed to set protocol version to 3";




    // verify binding

  if ($ldapbind) {
"LDAP bind successful...";

        echo "\n";

        print "Congratulations! $ldaprdn is now authenticated.";

    } else {
"LDAP bind failed...";

        print "Nice try, kid. Better luck next time!";





There are some other parameters which can be used to set the base search location and then the userid (uid) attribute can be used.  So only "guest1" would be entered as the userid and NOT the full DN.


Hope this help other potential guest users of our Free Online Development LDAP Server!!


About zFlex Software

zFlex Software have over of 25 years experience working with the IT field.  Over 15 years working directly with IBM products and projects in Enterprise System Environments.  We focus on IBM product installation, Infrastructure Setup and Solution Design in the Mainframe (z/OS), Linux, Solaris and Window platforms.   Knowledge of these various platforms makes our consulting very flexible for Integration tasks around these various platforms, enabling zFlex to meet your business needs.

© 2016 zFlex Software,LLC. All Rights Reserved. Designed By zFlex Software