我正在尝试对网站进行垃圾邮件检查,就像我的网站A,B,C,D ...我正在创建一个集中式垃圾邮件检查过滤器,例如xyz.com/spamcheck.php
我正在使用CURL将数据从网站A发布到xyz.com/spamcheck.php 在我的spamcheck.php中,我使用Akismet Fuspam库对其进行验证,并将响应返回到我的网站A,根据我的spamcheck的响应,我将决定发送邮件还是丢弃。
到目前为止,我还无法通过CURL将值发布到我的spamcheck.php并从中获得响应。
// DATA PROCESSING
$data = array();
$data['ip'] = get_client_ip();
$data['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
$data['referrer'] = $_SERVER['HTTP_REFERER'];
$data['comment_author'] = $_POST['first_name'];
$data['comment_author_email'] = $_POST['email'];
$data['comment_content'] = $_POST['message'];
$params = json_encode($data);
$url = "https://www.my-spam-check-url.com/spamcheck.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // On dev server only!
$spamResult = curl_exec($ch);
curl_close($ch);
$spamResult = json_decode($spamResult,true);
print_r($spamResult);
我希望输出为TRUE或FALSE。我收到空白回复
spamcheck.php
// Include Akismet F-U-Spam function.
include 'includes/akismet.fuspam.php';
// Function to get the client IP address
function get_client_ip() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
/*API KEY - 123XYZ*/
$comment = array();
$key = "123XYZ";
$type = "check-spam";
/* Get Posted Data from website */
$postedIp = $data['ip'];
$postedUserAgent = $data['user_agent'];
$postedReferrer = $data['referrer'];
$postedcomment_author = $data['comment_author'];
$postedcomment_author_email = $data['comment_author_email'];
$postedcomment_content = $data['comment_content'] ;
/* Data Processing End */
if(empty($postedIp) || $postedIp == 'UNKNOWN' || $postedIp == ''){
$ip = get_client_ip();
}
if(empty($postedUserAgent) || $postedUserAgent == ''){
$user_agent = $_SERVER['HTTP_USER_AGENT'];
}
if(empty($postedReferrer) || $postedReferrer == ''){
$referrer = $_SERVER['HTTP_REFERER'];
}
$permalink = $blog = $authUrl = "https://www.example.net/";
$comment['blog'] = $blog;
$comment['user_ip'] = $ip;
$comment['user_agent'] = $user_agent;
$comment['referrer'] = $referrer;
$comment['permalink'] = $permalink;
$comment['comment_type'] = "ContactUs";
$comment['comment_author'] = $postedcomment_author;
$comment['comment_author_email'] = $postedcomment_author_email;
$comment['comment_author_url'] = $authUrl;
$comment['comment_content'] = $postedcomment_content;
$spamCheckResult = fuspam( $comment , $type , $key );
echo $spamCheckResult;
答案 0 :(得分:0)
我正在查看您的代码,我不能确定print_r是否正在检查您的身份,但是如果是这样,请记住:
print_r(true)将输出1,而print_r(false)将输出“”,空白。
也许可以使用var_dump进行调试?
BR
答案 1 :(得分:0)
如果您的spamcheck.php
按照您的书面代码工作,则比上次使用echo
的{{1}}之前的工作要好。因此我将在返回您的实际结果之前删除空间或其他任何内容。