Giter VIP home page Giter VIP logo

ldapclient's Introduction

LDAPClient

LDAPClient is a PHP library designed to make LDAP operations easy and flexible. From basic queries to advanced LDAP functionalities, this library offers a wide range of features.

Features

  • Simplified LDAP Connection
  • User Authentication
  • Advanced Search Queries
  • Debugging Support

Installation

composer require faulkj/ldapclient

Methods & Usage

LDAPClient Class

__construct($server, $bindDN, $pass, $baseDN, $options)

Initiate a connection to the LDAP server.

  • $server: The LDAP server URL
  • $bindDN: The DN to bind with
  • $pass: The password for binding
  • $baseDN: The base DN for the directory
  • $options: List of LDAP fields to pull. Allows for custom attribute mappings to align with the specific LDAP system you're working with.

Example:

use FaulkJ\LDAPClient

$ldap = new LDAPClient(
   "ldap.forumsys.com",
   "cn=read-only-admin,dc=example,dc=com",
   "password",
   "dc=example,dc=com",
   [
      "id" => "uid"
   ]
);

debug($dbg)

Toggle debugging output for LDAP operations. When enabled, this provides verbose output for troubleshooting.

  • $dbg: Boolean to enable or disable debugging

Example:

$ldap->debug(true);

Returns:

  • Current debug state if no parameter is provided
  • The LDAPClient object itself, allowing for method chaining, if a parameter is provided

getJSON($filter, $attr = [], $dn = false, $fullDNs = false)

Converts the search result to a JSON format.

  • $filter: LDAP filter
  • $attr: Attributes to fetch
  • $dn: Optional DN to search under
  • $resolveDNs: Whether to resolve DNs
  • $stayBound: Whether to stay bound

Example:

die($ldap->getJSON("(ou=chemist*)", ["cn", "members" => "uniquemember"], null, true));

Returns: JSON-formatted string representing the search results.

login($id, $pass, $attr)

Authenticate a user and return their attributes.

  • $id: User ID
  • $pass: Password
  • $attr: Attributes to fetch

Example:

if($user = $ldap->login("riemann", "password", ["fullname" => "cn", "mail"])) {
   echo "{$user->fullname} successfully logged in!";
}
else echo "Invalid username or password!";

Returns:

  • User object with specified attributes if successful
  • false if authentication fails
  • null if the user is not found

member($user, $group, $options = [])

Check if a user is a member of a specific LDAP group or groups.

  • $user: The user ID to check
  • $group: Group or array of groups to check membership
  • $options: Optional array for additional attribute mappings (merges with default options)

Example:

if($ldap->member("mathematicians", "gauss", [
   "id"     => "ou",
   "member" => "uniquemember"
])) {
   echo "gauss is a mathematician!";
}

Returns:

  • true if the user is a member
  • false if the user is not a member
  • null if the user is not found

photo($user)

Retrieves the photo for a specified user.

Example:

$ldap->photo("simmons");

Returns: Outputs the image directly to the screen if available, a blank image if not

search($filter, $attr, $dn, $resolveDNs, $stayBound)

Perform an LDAP search.

  • $filter: LDAP filter
  • $attr: Attributes to fetch
  • $dn: Optional DN to search under
  • $resolveDNs: Whether to resolve DNs
  • $stayBound: Whether to stay bound

Example:

$res = $ldap->search(
   "(ou=chemist*)",
   [
      "cn",
      "members" => "uniquemember"
   ],
   null,
   true
);
echo implode("\n", $res->members);

Returns:

  • Array of LDAP records if multiple records are found
  • Single LDAP record if only one is found
  • null if no records are found

ldapclient's People

Contributors

faulkj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.