Scripting Blogs

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

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:

 

<?php

// 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("zflexldap.com")
    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";

          }

        else

        {

        echo "Failed to set protocol version to 3";

 

         }

 

    // verify binding

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

        echo "\n";

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


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

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

}

 

 

 

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

Search