Thursday, May 11, 2017

Oracle Solaris 11.3 PHP and LDAPS now work together

Well 2 years ago I complained about LDAPS did not work with PHP in Solaris 11.2 well with Oracle Solaris 11.3 and a recent SRU they are now working in partnership.

php -v
PHP 5.6.22 (cli) (built: Mar 22 2017 09:59:02)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

# cat ldaps.php
    ini_set('display_errors', 'On');
    $ds = "ldaps://";
    $ldaprdn  = "cn=admin,ou=users,dc=bbk,dc=ac,dc=uk";
    $ldappass = 'MyPassword';
    $ldapport = 636;

    // connect to ldap server
    $ldapconn = ldap_connect($ds, $ldapport)
    or die("Could not connect to LDAP server.");

    if ($ldapconn) {
        if (ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3)) {
          echo "Setting Protocol\n";
    } else {
          echo "Failed to set protocol version";
        ldap_set_option($ldapconn, LDAP_OPT_REFERRALS,0);
        // binding to ldap server
        $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

    // verify binding
    if ($ldapbind) {
        echo "Connected to LDAP\n";
    // $ds is a valid link identifier for a directory server
    if (ldap_get_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, $version)) {
           echo "Using protocol version $version\n";
    } else {
           echo "Unable to determine protocol version\n";

    $filter="(|(uid=". "testuser))";
    $sr=ldap_search($ldapconn, "ou=users,dc=bbk,dc=ac,dc=uk", $filter);
        $info = ldap_get_entries($ldapconn, $sr);
        echo $info[0]["dn"]."\n";
        echo $info[0]["uid"][0]."\n";
    } else {
        echo "Connection to LDAP Failed";

# php ldaps.php
Setting Protocol
Connected to LDAP
Using protocol version 3

No comments: