我正在创建一个跟踪像素,并以此答案为起点。但是,在我尝试将数据插入数据库之前,一切正常。那时我得到一个 500(内部服务器错误)。
这是我的代码:
<?php
$im=imagecreate(1,1);
$white=imagecolorallocate($im,255,255,255);
imagesetpixel($im,1,1,$white);
header("content-type:image/jpg");
imagejpeg($im);
imagedestroy($im);
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER['REMOTE_ADDR'];
function getUserIP() {
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER['REMOTE_ADDR'];
if(filter_var($client, FILTER_VALIDATE_IP)) {
$ip = $client;
} else if (filter_var($forward, FILTER_VALIDATE_IP)) {
$ip = $forward;
} else {
$ip = $remote;
}
return $ip;
}
$user_ip = getUserIP();
$ip_integer = ip2long($user_ip);
$web_url = 'myurl.com';
$sqlWebLeads = "INSERT INTO ip_details (ip_address, web_url)
VALUES ('$ip_integer','$web_url')";
$wpdb->query($sqlWebLeads);
?>
有任何想法吗?