PHP Doku:: Konvertiert DN in ein benutzerfreundliches Namensformat - function.ldap-dn2ufn.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSonstige DiensteLightweight Directory Access ProtocolLDAP Funktionenldap_dn2ufn

Ein Service von Reinhard Neidl - Webprogrammierung.

LDAP Funktionen

<<ldap_delete

ldap_err2str>>

ldap_dn2ufn

(PHP 4, PHP 5)

ldap_dn2ufn Konvertiert DN in ein benutzerfreundliches Namensformat

Beschreibung

string ldap_dn2ufn ( string $dn )

Die ldap_dn2ufn() Funktion wird verwendet um einen DN, angegeben mit dn, in einer benutzerfreundlicheren Form darzustellen, wobei die Typen-Namen wegfallen.


4 BenutzerBeiträge:
- Beiträge aktualisieren...
naaina at gmail dot com
18.02.2005 13:18
Don't know if anyone is interested in this, but this is a modified and more dynamic version of the posting below. Since ldap_dn2ufn takes ',' as delimiter for the UFNs, we'll also use it here. $pHowToBuild specifies, how the DN is going to be build.

Short example:

$myUFN = ldap_dn2ufn("cn=naaina, ou=container1, ou=container2, ou=container3, o=private, c=de");
echo $myUFN . "\n"; // will return "naaina, container1, container2, container3, private, de"

$myDN = $ldapObject->conv_ufn2dn($myUFN);
echo $myDN . "\n"; // will return "cn=naaina,ou=container1,ou=container2,ou=container3,o=private,c=de"

For the object name, $pHowToBuild["object"] is going to be used as prefix - for containers $pHowToBuild["container"] and for the last n elements $pHowToBuild["last"].

<?php
 
function ldap_ufn2dn (
  
$pUFN,
  
$pDelimiter = ",",
  
$pHowToBuild = array(
   
"object" => "cn",
   
"container" => "ou",
   
"last" => array("o", "c")
   )
  )
  {
  
$resultDN = null;
  
   if(!empty(
$pUFN)) {
    
/* Check $pHowToBuild */
    
if(is_array($pHowToBuild)) {
      
/* Check if required keys are existent */
      
if(array_key_exists("object", $pHowToBuild) &&
         
array_key_exists("container", $pHowToBuild) &&
         
array_key_exists("last", $pHowToBuild))
       {
        
$ufnArray = explode($pDelimiter, $pUFN);
        
$ufnLast  = count($ufnArray) - count($pHowToBuild["last"]);

        
/* Remove empty values */         
        
foreach($ufnArray as $objKey => $objVal)
           if(empty(
$objVal))
            
array_splice($ufnArray, $objKey, 1);
        
        
/* Now build the DN ... */
        
foreach($ufnArray as $objKey => $objVal) {
          
$objVal = trim($objVal);
       
           if(
$objKey == 0) {
            
/* For the object */
            
$resultDN .= $pHowToBuild["object"] . "=" . $objVal . ",";
           } elseif (
$objKey >= $ufnLast) {
            
/* For last parts of the DN */
            
$resultDN .= $pHowToBuild["last"][$objKey - $ufnLast] . "=" . $objVal;
             if((
$objKey - $ufnLast - 1) != 0) {
              
$resultDN .= ",";
             }
           } else {
            
/* For containers */
            
$resultDN .= $pHowToBuild["container"] . "=" . $objVal . ",";
           }
         }
       }
     }   
   }
  
   return
$resultDN;
  }
?>
alex at netflex dot nl
15.10.2002 13:09
The function of bryan will only work if you start with an Organization and using only an Organizational Unit as a container and the object is an CN.

For example:

$DN = "CN=DNS,CN=Authorized Login Methods,CN=Security";

echo ($DN = ldap_dn2ufn($DN)) . "\n";

echo ($DN = ldap_ufn2dn($DN)) . "\n";

will echo:

DNS,Authorized Login Methods,Security

CN=DNS,OU=Authorized Login Methods,O=Security
bryan at apachetoolbox dot com
25.07.2001 1:47
function ldap_unf2dn($unf,$delimeter=".") {
 $seperated = explode($delimeter,$unf); //split the unf up by the given delimeter
 $LastKey=count($seperated)-1;          //0 is the first key to total-1 would be the last key              
 foreach($seperated as $key => $value) {
  if ($key == 1) {              //first variable is the CN
   $dn="${dn}cn=$value,";
  } elseif ($key == $LastKey) { //last variable, so it's the O
   $dn="${dn}o=$value";
  } elseif ($value == "") {     //value is blank, so continue
   continue;
  } else {                      //just a typical OU
   $dn="${dn}ou=$value,";
  }
  
 };
return $dn;

}

$unf=".bryan.users.admin.apachetoolbox";
$dn=ldap_unf2dn($unf);
print "$dn" // will give me "cn=bryan,ou=users,ou=TS,o=apachetoolbox"
bryan at apachetoolbox dot com
25.07.2001 1:12
This function will convert "cn=bryan,ou=users,ou=admin,o=apachetoolbox" to "bryan,users,admin,apachetoolbox".



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)