note 105269 modified in function.ldap-sasl-bind by danbrown
| From: | danbrown@php.net | Date: | Sun, 07 Aug 2011 15:38:26 +0000 |
| Subject: | note 105269 modified in function.ldap-sasl-bind by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-182298@lists.php.net to get a copy of this message | ||
Code snippet demonstrating how to establish a TLS-encrypted connection to an OpenLDAP server from an
Apache webserver and authenticate using a user's Kerberos credentials. Credentials MUST be
delegated to the web server for this method to work.
<?php
putenv("KRB5CCNAME={$_SERVER['KRB5CCNAME']}");
$resource = ldap_connect("ldap.example.com")
or die("Failed to connect to LDAP server.");
echo "Connected to LDAP server.<br />";
//these options may not be necessary in all environments
ldap_set_option($resource, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($resource, LDAP_OPT_REFERRALS, 0);
$result = ldap_start_tls($resource)
or die("Failed to start TLS");
echo "Started TLS.<br />";
$result = ldap_sasl_bind($resource, NULL, '', 'GSSAPI', 'EXAMPLE.COM',
'', '')
or die("Failed to GSSAPI bind.<br />");
echo "GSSAPI bound.";
?>
--was--
Code snippet demonstrating how to establish a TLS-encrypted connection to an OpenLDAP server from an
Apache webserver and authenticate using a user's Kerberos credentials. Credentials MUST be
delegated to the web server for this method to work.
<?php
putenv("KRB5CCNAME={$_SERVER['KRB5CCNAME']}");
$resource = ldap_connect("ldap.example.com")
or die("Failed to connect to LDAP server.");
echo "Connected to LDAP server.<br />";
//these options may not be necessary in all environments
ldap_set_option($resource, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($resource, LDAP_OPT_REFERRALS, 0);
$result = ldap_start_tls($resource)
or die("Failed to start TLS");
echo "Started TLS.<br />";
$result = ldap_sasl_bind($resource, NULL, '', 'GSSAPI', 'EXAMPLE.COM',
'', '')
or die("Failed to GSSAPI bind.<br />");
echo "GSSAPI bound.";
?>
See also: http://left.subtree.org/2007/06/26/phpldapadmin-and-kerberos/
http://php.net/manual/en/function.ldap-sasl-bind.php