我正在使用此脚本将引荐来源网址设置为 url,或者如果引荐来源网址为空或设置了 cookie,请点击图片。下面的代码是我到目前为止所拥有的,如果我将 curl 函数部分单独放在一个文件中,但我无法将它与 cookie 部分放在一起,则它可以工作。
错误是调用未定义的函数 geturl()
<?php
$image = 'image_url';
if($_COOKIE["6346"] == 1) {
$show = 0;
}
else {
$show = 1;
$hours = rand(24,68);
setcookie('6346', 1, time()+(60*60*$hours));
}
if (!empty($_SERVER['HTTP_REFERER'])) {
$goodreferer = 0;
}
else {
$goodreferer = 1;
}
if ($show == 1 && $goodreferer == 0) {
echo geturl('url(dot)com', 'referer(dot)com');
function geturl($url, $referer) {
$headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg,text/html,application/xhtml+xml';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$useragent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERAGENT, $useragent);
curl_setopt($process, CURLOPT_REFERER, $referer);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
}
else {
header('Location: ' . $image);
exit;
}
?>