0

我在 php.ini 中收到了一些无法识别的偏移警告。

<?php

/*****************************************************************/
/*****************************************************************/
/**** Queries Active Directory For Overview Off All Employees ****/
/*****************************************************************/
/*****************************************************************/

/*-------------*/
/* Credentials */
/*-------------*/

    $ldapserver = 'srv-dc-01.vex.local';
    $ldapuser = 'SamL@vex'; 
    $ldappass = 'xxxx!';
    $ldaptree = "OU=Users,OU=MyBusiness,DC=vex,DC=local";

    $secret = '}84lSB+-cdH{?[';

/*------------------------*/
/* Connect & Authenticate */
/*------------------------*/

    $ldapconn = ldap_connect($ldapserver) or die("Could not connect to LDAP server.");

    ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
    ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); // For LDAP v3

    $ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass) or die ("Error trying to bind: ".ldap_error($ldapconn));

/*------------------------*/
/* Query Active Directory */
/*------------------------*/

    $result = ldap_search($ldapconn,$ldaptree, "(cn=*)", array("cn","title","mail","telephonenumber","thumbnailphoto")) or die ("Error in search query: ".ldap_error($ldapconn));

    $data = ldap_get_entries($ldapconn, $result);

    $count = $data['count'];

?>

<html>
    <head>
        <title>sive</title>
        <style> 
            .box {
                float:left;
                width:400px;
                height:100px;
                border-style:dashed;
                border-width:2px;
                border-color:grey;
                padding:5px;
                margin:5px;
            }
            .picture {
                float:left;
                width:100px;
            }
        </style>
    </head>
    <body>

<?php

    for($i=0;$i<$count;$i++)
    {


        $blacklist = array("BES Admin","Network Administrator","SBSMonAcct","Directory Updater","NL Admin","Standard User","Standard User with administration links","SSL Admin");
        foreach ($blacklist as $key => $value){
            if($data[$i]["cn"][0] === $value) { continue; } 
        }

        /*if($data[$i]["cn"][0] === "BES Admin") { continue; }
        if($data[$i]["cn"][0] === "Network Administrator") { continue; }
        if($data[$i]["cn"][0] === "SBSMonAcct") { continue; }
        if($data[$i]["cn"][0] === "Directory Updater") { continue; }
        if($data[$i]["cn"][0] === "NL Admin") { continue; }
        if($data[$i]["cn"][0] === "Standard User") { continue; }
        if($data[$i]["cn"][0] === "Standard User with administration links") { continue; }
        if($data[$i]["cn"][0] === "SSL Admin") { continue; }
        if($data[$i]["cn"][0] === "Vente-Exclusive.com Club") { continue; }
        if($data[$i]["cn"][0] === "Vente-Exclusive.com Logistics") { continue; }
        if($data[$i]["cn"][0] === "SQLServer2005MSSQLUser\$WIN-EUGSO7LO7PY\$BLACKBERRY") { continue; }
        if($data[$i]["cn"][0] === "Sharepoint TFS") { continue; }
        if($data[$i]["cn"][0] === "Jobs Autoreply") { continue; }
        if($data[$i]["cn"][0] === "Printer Lookup2") { continue; }
        if($data[$i]["cn"][0] === "Printer Lookup") { continue; }
        if($data[$i]["cn"][0] === "VPN Lookup") { continue; }
        if($data[$i]["cn"][0] === "WallaceBackups") { continue; }
        if($data[$i]["cn"][0] === "Info - Yaminta") { continue; }
        if($data[$i]["cn"][0] === "Service - Yaminta") { continue; }
        if($data[$i]["cn"][0] === "QA -. Test Mailbox") { continue; }
        if($data[$i]["cn"][0] === "Vente-Exclusive.com Android App") { continue; }
        if($data[$i]["cn"][0] === "Vente-Exclusive.com Social") { continue; }
        if($data[$i]["cn"][0] === "FashionDays") { continue; }
        if($data[$i]["cn"][0] === "KTN - Vente-Exclusive Admin") { continue; }
        if($data[$i]["cn"][0] === "Skype") { continue; }
        if($data[$i]["cn"][0] === "WSSSERVICE") { continue; }
        if($data[$i]["cn"][0] === "Accounting Robot") { continue; }
        if($data[$i]["cn"][0] === "NL - Amsterdam - Main meeting room") { continue; }
        if($data[$i]["cn"][0] === "Ticketing Authenticator") { continue; }
        if($data[$i]["cn"][0] === "SQLServerMSSQLServerADHelperUser\$SRV-DC-01") { continue; }
        if($data[$i]["cn"][0] === "SQLServer2005SQLBrowserUser\$SRV-DC-01") { continue; }
        if($data[$i]["cn"][0] === "SQLServerMSSQLServerADHelperUser\$VEX-SRV-NL-01") { continue; }
        if($data[$i]["cn"][0] === "SQLServer2005SQLBrowserUser\$VEX-SRV-NL-01") { continue; }
        if($data[$i]["cn"][0] === "SQLServerMSSQLServerADHelperUser\$SRV-DC-02") { continue; }
        if($data[$i]["cn"][0] === "SQLServer2005SQLBrowserUser\$SRV-DC-02") { continue; }
        if($data[$i]["cn"][0] === "BE_HUM65_02_London") { continue; }
        if($data[$i]["cn"][0] === "BE_HUM65_02_NewYork") { continue; }
        if($data[$i]["cn"][0] === "BE_HUM65_02_Paris") { continue; }
        if($data[$i]["cn"][0] === "BE_HUM65_02_Milan") { continue; }
        if($data[$i]["cn"][0] === "BE_HUM65_02_Antwerp") { continue; }
        if($data[$i]["cn"][0] === "BE_HUM65_02_HongKong") { continue; }
        if($data[$i]["cn"][0] === "BE_HUM65_02_Barcelona") { continue; }
        if($data[$i]["cn"][0] === "BE_HUM111_01_Coton") { continue; }
        if($data[$i]["cn"][0] === "BE_HUM111_01_Silk") { continue; }
        if($data[$i]["cn"][0] === "BE_HUM111_01_Leather") { continue; }
        if($data[$i]["cn"][0] === "0024d63772ec") { continue; }
        if($data[$i]["cn"][0] === "0c607621979d") { continue; }
        if($data[$i]["cn"][0] === "000085ffbde8") { continue; }
        if($data[$i]["cn"][0] === "0088653e354e") { continue; }
        if($data[$i]["cn"][0] === "Ops Monitor") { continue; }
        if($data[$i]["cn"][0] === "DG_IT_Logistics") { continue; }
        if($data[$i]["cn"][0] === "DG_StrongView") { continue; }
        if($data[$i]["cn"][0] === "OPS Support") { continue; }
        if($data[$i]["cn"][0] === "SYS Support") { continue; }*/


        echo "<div class=\"box\">";
        $userData = $data[$i];

        if(array_key_exists('thumbnailphoto', $userData))
        {
            $fileName = tempnam(sys_get_temp_dir(), 'vex');

            $imageParam = basename($fileName);
            $keyParam = md5($secret . $imageParam);

            $fp = fopen($fileName, "wb") or die("Can't open $fileName for writing");

            fwrite($fp, $userData['thumbnailphoto'][0]);
            fclose($fp);

            echo "<div class=\"picture\"><img src=\"pic.php?image=" . rawurlencode($imageParam) . "&key=" . rawurlencode($keyParam) . "\" width=\"96\"></div>";
        }

        echo "Full name: ". $data[$i]["cn"][0] ."<br />";

        if(isset($data[$i]["title"][0])) {
                echo "Title: ". $data[$i]["title"][0] ."<br />";
            } else {
                echo "Title: No title found<br />";
            }
        if(isset($data[$i]["mail"][0])) {
                echo "Email: <a href='mailto:". $data[$i]["mail"][0] ."'> ". $data[$i]["mail"][0] ."</a><br />";
            } else {
                echo "Email: No mail found<br />";
            }
        if(isset($data[$i]["telephonenumber"][0])) {
                echo "Phone: ". $data[$i]["telephonenumber"][0] ."<br /><br />";
            } else {
                echo "Phone: No number found<br /><br />";
            }
    echo "</div>";

    }

/*------------------*/
/* Close Connection */
/*------------------*/

ldap_unbind($ldapconn);

?>

    </body>
</html>

谢谢

编辑:

错误

注意:未定义的偏移量:第 72 行 C:\wamp\www\vex\ad.php 中的 8

我想要做的是:我有一个数组,但在那个数组中有我不想要的值(我不能做更具体的查询(在 OU 中使用 LDAP 查询,但是有计算机在那里像“管理员”或“打印机”,我不想在我的概述中,因为我只需要“真正的”员工))

所以有我的黑名单

如果做 if($data[$i]["cn"][0] === "blabla") { continue; },但后来我必须这样做 52 次,而且还有很多继续......

编辑:

    $skip = 0;

    foreach ($blacklist as $key => $value){
        if($data[$i]["cn"][0] === $value) { $skip = 1; } 

    }
    if($skip)
        continue;

这会跳过黑名单数组中的所有值,而不会发出 100000 个通知警告!

4

1 回答 1

0

您的数组只有键 0-7。如果 的值$i不是这些值之一,则它是未定义的偏移量。print_r($blacklist);显示键及其值:

Array
(
    [0] => BES Admin
    [1] => Network Administrator
    [2] => SBSMonAcct
    [3] => Directory Updater
    [4] => NL Admin
    [5] => Standard User
    [6] => Standard User with administration links
    [7] => SSL Admin
)

确保您的变量$count已定义并且值不大于 8,但我猜您想要的正是 8:

$count = count($blacklist);

或者您可以将循环定义为:

$blacklist = array("BES Admin","Network Administrator","SBSMonAcct","Directory Updater","NL Admin","Standard User","Standard User with administration links","SSL Admin");
for($i=0; $i<count($blacklist); $i++){
    if($data[$i]["cn"][0] === $blacklist[$i]) { continue; } 
}

但是,在使用数组时,我更喜欢使用foreach它,因为它会为您跟踪数组项的数量:

$blacklist = array("BES Admin","Network Administrator","SBSMonAcct","Directory Updater","NL Admin","Standard User","Standard User with administration links","SSL Admin");
foreach ($blacklist as $key => $value){
    if($data[$i]["cn"][0] === $value) { continue; } 
}
于 2013-08-14T08:04:04.667 回答