$url = "http://www.baidu.com";
$host = 'www.baidu.com';
$data = "要發送的數據";
$ip='121.186.1.57';
$headers['CLIENT-IP'] = $ip;
$headers['X-FORWARDED-FOR'] = $ip;
$headerArr = array();
foreach( $headers as $n => $v ) {
$headerArr[] = $n .':' . $v;
}
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt ($ch, CURLOPT_HTTPHEADER , $headerArr ); //構造IP
// 咱們在POST數據哦!
curl_setopt($ch, CURLOPT_POST, 1);
// 把post的變量加上
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$file_contents = curl_exec($ch);
curl_close($ch);
var_dump($file_contents);瀏覽器
第二種:採用socket請求的方式緩存
$host = '192.168.1.100';網絡
$fp = fsockopen($host,80);
if(!$fp)
{
die('建立鏈接失敗,檢查主機地址或網絡鏈接');
}
//構造http請求串
$send = "POST $path HTTP/1.1\r\n";
$send .= "Host: $host\r\n";
$send .= "Content-type: application/x-www-form-urlencoded\r\n";
// $send .= 'X-FORWARDED-FOR:8.8.8.8' . "\r\n";
$send .= "CLIENT-IP:$per_ip\r\n";//僞造IP
$send .= "Content-length: " . strlen($data) . "\r\n";
$send .= "Connection: close\r\n\r\n";
$send .= $data . "\r\n\r\n";
//發送請求
fwrite($fp, $send, strlen($send));
//讀取返回信息
$back = '';
while(!feof($fp))
{
$back .= fread($fp, 1024);
}
fclose($fp);
if(strpos($back, '成功'))
{
$flag = '成功';
sleep(1);
}
app