使用PHP CURL发布表单数据时使用客户端IP地址

时间:2015-03-02 21:53:50

标签: php forms curl ip

我正在尝试使用curl将数据发布到表单并且一切正常但除了当我发送表单时,它在发送表单时使用服务器ip地址,但我真正想做的是设置一个自定义用户代理(我之所以需要使用curl),我需要客户端的ip保持不变。

这是我现在正在使用的代码。

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);

//The next line set the user agent to a custom one.

curl_setopt($ch, CURLOPT_USERAGENT, "Mobile UA :" . $rrand );
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);

我希望curl在发送表单时使用客户端IP地址,而不是托管php脚本的服务器的地址。如果可以设置自定义服务器地址来发布表单,那也会有所帮助。

1 个答案:

答案 0 :(得分:2)

如果您能够伪造请求以使其看起来像是来自用户的网络,那么响应也将转到用户的网络,在那里没有任何东西可以等待它。

所以不,这是不可能的。