plz
plz

Reputation: 71

How to use a different server IP with PHP/cURL?

I have a server with different IPs assigned, how can I specifiy a different IP to be used by cURL?

Upvotes: 7

Views: 8959

Answers (2)

Russell Dias
Russell Dias

Reputation: 73282

You will have to use the CURLOPT_INTERFACE option:

The name of the outgoing network interface to use. This can be an interface name, an IP address or a host name.

It can be used in the following manner:

curl_setopt($ch, CURLOPT_INTERFACE, "XXX.XXX.XXX.XXX");

This ofcourse, only accepts IPs and hostnames from your local machine.

Upvotes: 11

Pramendra Gupta
Pramendra Gupta

Reputation: 14873

Here quick tip

$tuCurl = curl_init(); 
curl_setopt($tuCurl, CURLOPT_URL, "http://ip/path");
//curl_setopt($tuCurl, CURLOPT_URL, "http://domain");

example in ubuntu

change /etc/apache2/sites-available/default

curl_setopt($tuCurl, CURLOPT_URL, "http://project1.local");
curl_setopt($tuCurl, CURLOPT_URL, "http://127.0.0.1/project1");

Upvotes: 0

Related Questions