/Main_Page

::You must have ninja focus to complete your mission::NinjaFocus::

LDAP PHP

Views:


Slightly useful, old and basic function for listing attributes of objects in LDAP when programming in PHP


<?php
/*
        Copyright 2005 Kieran Whitbread + Contributors on www.php.net

        Distributed under the terms of the GNU General Public License.
        A copy of the license should be in a file called COPYING in the same
        directory as this file. You can also view the license online at
        http://www.gnu.org/licenses/gpl.txt

        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

function get_attributes($filter,$required_attributes=array('givenname','sn', 'mail'),$ldap_server='127.0.0.1',$base_dn='o=vsfc')
{
	$ldap_connection=ldap_connect($ldap_server) or die("Could not connect to LDAP server.");
	$ldap_binding=ldap_bind($ldap_connection);
	if ($ldap_binding)
	{
		$ldap_results=ldap_search($ldap_connection, $base_dn, $filter,$required_attributes);
		$ldap_entries=ldap_get_entries($ldap_connection, $ldap_results);
		ldap_unbind($ldap_connection);
		return $ldap_entries;
	}
}
?>

Main Menu

Personal tools

Toolbox