PHP Classes

File: php_configure_openldap.php

Recommend this page to a friend!
  Classes of ask sa sa   PHP Artificial Intelligence Example Code Generated by OpenAI   php_configure_openldap.php   Download  
File: php_configure_openldap.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: PHP Artificial Intelligence Example Code Generated by OpenAI
OpenAI-generated code in PHP and other languages
Author: By
Last change:
Date: 1 year ago
Size: 1,515 bytes
 

Contents

Class file image Download
<?php

$ldap_host
= "ldap://localhost";
$ldap_port = 389;

// Connect to the LDAP server
$ldap_conn = ldap_connect($ldap_host, $ldap_port);

if (
$ldap_conn) {
   
// Bind to the LDAP server as the administrator
   
$ldap_bind = ldap_bind($ldap_conn, "cn=admin,dc=example,dc=com", "password");

    if (
$ldap_bind) {
       
// Add the domain entry to the LDAP directory
       
$domain_dn = "dc=example,dc=com";
       
$domain_entry = array(
           
"objectClass" => "domain",
           
"dc" => "example",
        );
       
$result = ldap_add($ldap_conn, $domain_dn, $domain_entry);

        if (
$result) {
            echo
"Successfully added domain entry\n";
        } else {
            echo
"Failed to add domain entry: " . ldap_error($ldap_conn) . "\n";
        }

       
// Add the admin entry to the LDAP directory
       
$admin_dn = "cn=admin,dc=example,dc=com";
       
$admin_entry = array(
           
"objectClass" => "simpleSecurityObject",
           
"cn" => "admin",
           
"userPassword" => "password",
        );
       
$result = ldap_add($ldap_conn, $admin_dn, $admin_entry);

        if (
$result) {
            echo
"Successfully added admin entry\n";
        } else {
            echo
"Failed to add admin entry: " . ldap_error($ldap_conn) . "\n";
        }
    } else {
        echo
"Failed to bind to LDAP server: " . ldap_error($ldap_conn) . "\n";
    }

   
// Close the LDAP connection
   
ldap_close($ldap_conn);
} else {
    echo
"Failed to connect to LDAP server\n";
}