用PHP输出LDAP查询结果

来源:互联网 发布:地图生成软件 编辑:程序博客网 时间:2024/04/27 18:41
    做好Postfix+LDAP后,一直想写个程式,自动抓取LDAP中的邮箱地址,不用手动更改全局邮箱地址再发布,今天终于如愿,主要参考如下网页,在些感谢:

一个漂亮的输出MySql数据库表结构的PHP页面 
http://babyhe.blog.51cto.com/1104064/1118372
使用PHP连接LDAP服务器
http://www.justwinit.cn/post/591/

我的PHP源码:

点击(此处)折叠或打开

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <style type="text/css">
  6. <!--
  7. body,table{
  8.         font-size:13px;
  9. }
  10. table{
  11.         table-layout:fixed;
  12.         empty-cells:show;
  13.         border-collapse: collapse;
  14.         margin:0 auto;
  15.   border:1px solid #cad9ea;
  16. }
  17. th{
  18.         height:22px;
  19.   font-size:13px;
  20.   font-weight:bold;
  21.   background-color:#CCCCCC;
  22.   text-align:center;
  23. }
  24. td{
  25.         height:20px;
  26. }
  27. .tableTitle{font-size:14px; font-weight:bold;}

  28. .STYLE1 {color: #FF0000}
  29. </style>
  30. <title>Email Address</title>
  31. </head>

  32. <body>
  33. <div style="margin:0 auto;width:800px; border:1px #006600 solid; font-size:12px; line-height:20px;">
  34.   <div style="width:100%;height:30px; font-size:16px; font-weight:bold; text-align:center;">
  35.   XXXX--郵箱清單<br />
  36.   <font style="font-size:14px; font-weight:normal;"><b><span class="STYLE1">更新時間</span></b><?php echo date("Y-m-d h:i:s"); ?></font> </div>
  37.   <?php
  38.   
  39.   $connect_id=ldap_connect("x.x.x.x");
  40.   $result_array=array("cn","mail","mailQuota");
  41.   $search_id=ldap_search($connect_id,"virtualDomain=x.com,o=extmailAccount,dc=x.com", "cn=*",$result_array);
  42.   $result_array = ldap_get_entries($connect_id,$search_id);
  43.   for($i=0;$i<$result_array["count"];$i++)
  44.     {
  45.     $format_array[$i][0]=strtolower($result_array[$i]["cn"][0]);
  46.     $format_array[$i][1]=strtolower($result_array[$i]["mail"][0]);
  47.     $format_array[$i][2]=strtolower($result_array[$i]["mailQuota"][0]);
  48.     }

  49.     sort($format_array);
  50. /* for($row=0;$row<$result_array["count"];$row++)
  51.     {
  52.      //print_r($row); */
  53.   ?>
  54.       <div style="margin:0 auto; width:100%; padding-top:10px;">
  55.       <br/>
  56.       </div>
  57.        <table width="100%" border="1">
  58.             <thead>
  59.          <th width="10">ROW</th>
  60.           <th width="50">姓名</td>
  61.           <th width="100">郵箱地址</td>
  62.          <th width="100">郵箱限額</td>
  63.          </thead>
  64.     <?php
  65.     //    for($i=0;$i<=$row$result_array["count"];$i++)
  66.         for($i=0;$i<=$result_array["count"];$i++)
  67.         {
  68.         $cn=$format_array[$i][0];
  69.         $mail=$format_array[$i][1];
  70.         $quota=$format_array[$i][2];
  71.         ?>
  72.         <tr>
  73.             <td align="center"><?php echo $i ?></td>
  74.             <td align="left"><b><?php echo $cn ?></b></td>
  75.             <td align="left"><?php echo $mail ?></td>
  76.             <td align="left"><?php echo $quota ?></td>
  77.         </tr>
  78.         <?php
  79.         }
  80.         ?>
  81.     </table>
  82.     <?php
  83.     //}
  84.     ldap_close($connect_id);
  85.     ?>

  86. </div>
  87. </body>
  88. </html>





实现效果(遗憾的是邮箱限额未能带出,再确认中):
阅读(9) | 评论(0) | 转发(0) |
0

上一篇:一个漂亮的输出MySql数据库表结构的PHP页面

下一篇:网页自动跳转的5中方法

相关热门文章
  • 天津二手房市近日开始降温 买...
  • 河南省消协提醒买卖二手房警惕...
  • UBOOT-2012-10在OK6410平台的...
  • 华美远航(北京)投资有限公司...
  • Accept-Encoding: gzip,deflat...
  • test123
  • 编写安全代码——小心有符号数...
  • 使用openssl api进行加密解密...
  • 一段自己打印自己的c程序...
  • sql relay的c++接口
  • IBM DS3400 盘阵怎么查看是单...
  • 启动auditd时,报错如下,怎么...
  • CGSL系统中root密码正确,但无...
  • 在CGSL系统中,如何为不同的用...
  • CGSL系统如何设置交换分区的大...
给主人留下些什么吧!~~