php-general Digest 18 Jul 2010 19:01:41 -0000 Issue 6852

Topics (messages 306970 through 306971):

Re: recursive
        306970 by: Ashley Sheridan

Getting only attribute and not its values when doing LDAP calls to 2003 AD 
server
        306971 by: Unix Nair

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
On Sun, 2010-07-18 at 09:49 +0430, shahrzad khorrami wrote:

> hi all :)
> here is a xml file:
> 
> <directive>
>    <rule>
>       <rules>
>              <rule>  </rule>
>              <rule>  </rule>
>       </rules>
>    </rule>
> </directive>
> 
> <directive>
>    <rule>
>       <rules>
>              <rule>  </rule>
>              <rule>  </rule>
>       </rules>
>    </rule>
> </directive>
> .
> .
> .
> .....
> I have a xml file with a name for example(test.xml)..
> and 3 tables of database, (group,directives,rules)
> group is for recording the name of the opened xml file,  directives is for
> storing the attributes of directive tag and rules is for 'rule' tag's
> attributes.
> 
> I know I must use of recursive function.. but how? first read name of the
> xml file and store it in group table, then the content of the file and fill
> the directive and rules table...
> 
> 
> <directive  .*... attrs go to directives table..*.>
>    <rule * ...attrs go to rules table...*.>
>       <rules * ..no attrs.*.>
>              <rule   *...attrs go to rules table...*.>  </rule>
>              <rule  *...attrs go to rules table..*..>  </rule>
>       </rules>
>    </rule>
> </directive>
> 
> 
> how to implement it in php?
> 
> Thanks,
> Shahrzad


I don't think a recursive function is what you need here, that's
something which has to call itself over and over.

I assume there may be multiple xml files you need to parse?

What you need is a series of nested loops. The first one loops through
the list of xml filenames you need to parse (you can get this list from
a directory listing if you need), the second goes through each
<directive> tag, the third through the <rule> tags.

The attributes of each tag can be pulled out quite easily. Are these a
list of known attributes, or unknown? If you know what they are, you can
hard-code retrieving their values, but if not, another loop will be able
to fetch these out for you.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Hi
I followed the examples mentioned in ldap functions pages at
www.php.net<http://www.google.com/url?sa=D&q=www.php.net&usg=AFQjCNHoc0Ba_1Imkk_33DysfxCk38dNag>.

But I am getting only the attribute names and not the values stored in
attributes array. Can some one give me some tips to fix my issue.
Here is my configuration.

Apache/2.0.59 HP-UX_Apache-based_Web_Server (Unix) DAV/2 PHP/5.2.13
on  HP-UX 11.11 and php is using OpenLDAP, vendor version 20122

Here is my php code.
==========================================================
<?php
// First program written for testing Microsoft AD Authentication
// Written by Madhu Kangara on 07/16/2010

$host = "secldapwest.gsm1900.org";
$myLogin = "gsm1900\\mkangar";
$myPass = "password_here";
$resource = ldap_connect($host) or die("Could not connect to AD
Server.");

// PHP will connect to server on the port 389
// Then you have to authenticate with an AD user to access to his
information.

if ($resource)
 {
 //Authentication to the AD with a windows login, password
 //$bind = ldap_bind($resource, $myLogin."@".$host, $myPass);
 // binding to AD server
 $bind = ldap_bind($resource, $myLogin, $myPass);

 // verify binding
 if ($bind)
  {
  echo "AD bind successful<br>\n";
  //$dn contain information asked by Windows server to browse the
correct AD tree.
  $dn ="OU=User Accounts,DC=gsm1900,DC=org";
  $filter="sAMAccountName=mkangar";
  $justthese =
array("surname","mail","memberof","name","givenname","sn");
  $sizelimit=15; // limit to maximum 15 return rows
  $result = ldap_search($resource,$dn,$filter,$justthese,$sizelimit);
  $result = ldap_search($resource,$dn,$filter,$justthese);
  $info = ldap_get_entries($resource, $result);
  var_dump($info);
  echo "<br>\n";
  echo $info["count"]. " entries returned<br>\n";
  echo "first surname entry " . $info[0]["surname"][0]. "<br>\n";
  echo "first mail entry " . $info[0]["mail"][0]. "<br>\n";
  echo "first memberof entry " . $info[0]["memberof"][0]. "<br>\n";
  echo "first name entry " . $info[0]["name"][0]. "<br>\n";
  echo "first givenname entry " . $info[0]["givenname"][0]. "<br>\n";
  echo "first sn entry " . $info[0]["sn"][0]. "<br>\n";
  echo "DN: " . $info[0]["dn"]. "<br>\n";
  echo "Number of attributes in 0th entry " . $info[0]["count"]. " <br>
\n";
  for ($i=0; $i<$info["count"];$i++)
   {
   for ($j=0;$j<$info[$i]["count"];$j++)
    {
    echo $info[$i][$j].": ".$info[$i][$info[$i][$j]][0]."\n";
    }
   }
  }
 else
  {
  echo "AD bind failed<br>\n";
  }
 ldap_close($resource);
 } // end of if ($resource)
?>
================================================
Here is the output from webpage. You can see that it is not displaying the
values. What am I doing wrong. Do I need to perform any configuration
settings in ldap.conf file at my side?
===============================================
AD bind successful
array(2) { ["count"]=> int(1) [0]=> array(2) { ["count"]=> int(0)
["dn"]=> string(93) "CN=MKangar,OU=Data Center Ops,OU=Systems
Operations,OU=COS,OU=User Accounts,DC=gsm1900,DC=org" } }
1 entries returned
first surname entry
first mail entry
first memberof entry
first name entry
first givenname entry
first sn entry
DN: CN=MKangar,OU=Data Center Ops,OU=Systems Operations,OU=COS,OU=User
Accounts,DC=gsm1900,DC=org
Number of attributes in 0th entry 0
===================================================

--- End Message ---

Reply via email to