Vote multiple times using CURL sessions and proxy
<?php
/**
*
* Vote multiple times using CURL sessions and proxy
*
* @param string $url load the website
* @param array $field submit fields (fieldname => fieldvalue)
* @param string $proxy proxy:port
* @return string
*
*/
function proxy($url, $fields, $proxy) {
foreach($fields as $key=>$value) { $fields_string .= $key . '=' . $value . '&'; }
rtrim($fields_string, '&');
//generate random browser version so we can act as a real user
$agents = array(
0 => 'Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20100101 Firefox/8.0',
1 => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR '
. '1.1.4322; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)',
2 => 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2'
);
$agent = $agents[rand(0, count($agents)-1)];
//first we get the url and store the session info into a cookie
//the block below can be excluded if there's no session protection
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($curlHandle, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_close($ch);
//load the url again and vote
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($curlHandle, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}