如何强制CURL使用IP客户发送请求?

时间:2017-09-04 09:48:51

标签: php curl php-curl

page1.php中

<?php
$myip = $_SERVER['REMOTE_ADDR'];
$url = ".../page2.php";

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$resultip = curl_exec($curl);
curl_close($curl);

echo "My IP: ".$myip."<br>IP CURL use: ".$resultip;
?>

使page2.php

<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo $ip;
?>

结果:

我的IP: 14.185.13.158

IP CURL使用: 198.143.134.70

如何获取自己的IP (使用$ _SERVER [&#39; REMOTE_ADDR&#39;]),而不是CURL的IP?

0 个答案:

没有答案