好吧,我放棄了。各位大神幫幫忙?
我有一個腳本,它連接到一個 gmail 帳戶,提取 IP 地址,并將它們寫入一個平面檔案,我的 PHP 標頭拒絕通過 IP 訪問站點(電子郵件形式的垃圾郵件發送者)。
問題是,在我的檔案末尾,在一堆 IP 之后,我得到了“Array”這個詞(如下所示)
99.154.188.141
94.180.207.5Array
$ips = $this->server->fetchEmails($this->checkEmailCriteria, [$this->parser, 'getIPAddress'], [$this, 'notifyAdmin']);
if ($ips) {
$this->updateBlockList($ips);
}
public function fetchEmails($criteria, $filter, $success) {
$inbox = new PHPMailer();
$inbox = imap_open(
"{imap.gmail.com:993/imap/ssl}" . $this->gmailInboxFolder,
$this->gmailUsername,
$this->gmailPassword,
FT_PEEK
) or die($this->strConnectionFailed . imap_last_error());
$emails = imap_search($inbox, $criteria, SE_UID);
$found = [];
if ($emails) {
foreach ($emails as $id) {
$message = imap_fetchbody($inbox, $id, 1, FT_UID);
$message = quoted_printable_decode(trim($message));
$message = html_entity_decode($message);
$ip = $filter($message);
if ($ip) {
echo $ip;
array_push($found, $IP);
}
}
}
imap_close($inbox, CL_EXPUNGE);
return $found;
}
private function updateBlockList($ips) {
$blockedIPs = file($this->blockFile);
$blockedIPs = array_merge($blockedIPs, [$ips]);
$blockedIPs = array_filter($blockedIPs);
$blockedIPs = array_unique($blockedIPs);
sort($blockedIPs);
$this->writeFile(
$this->blockFile,
$blockedIPs
);
}
private function writeFile($file, $contents) {
file_put_contents(
$file,
$contents
);
}
uj5u.com熱心網友回復:
我認為這是將“陣列”一詞放在檔案末尾的問題的一部分。
$blockedIPs = array_merge($blockedIPs, [$ips]);
$ips 已經是一個陣列,但在合并之前將它放入另一個陣列中。
但也要注意 aynber 在評論中所說的話。我認為$ips由于變數命名問題,陣列可能是空的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/374948.html
標籤:php
上一篇:在Laravel8中將一個陣列劃分為兩個陣列的干凈方法
下一篇:上傳時運行PHP檔案
