Link to home
Start Free TrialLog in
Avatar of oldmoondog
oldmoondogFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to use CURLOPT_INTERFACE to make requests via multiple IP addresses

I have multiple IP's on my public CentOS box, and can make requests via all of them using PHP / cURL in the form
       
curl_setopt($ch, CURLOPT_INTERFACE, "xxx.xxx.xxx.xxx");

Open in new window


However, I want to pass in the relevant IP dynamically. When I try in the form:

curl_setopt($ch, CURLOPT_INTERFACE, $currentIP);

Open in new window


Where $currentIP contains the IP address (xxx.xxx.xxx.xxx) it fails.

Any suggestions?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Gatherer_Hade
Gatherer_Hade

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of oldmoondog

ASKER

Hi,

Thanks for your response.
I have already printed out $currentIP value when debugging the script, and it's exactly what I expected.

When I hard code the IP into the       

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

it works fine.

Therefore I concluded it must be something to do with how I'm passing the value into the curl_setopt statement.

Have tried
$currentIP
"$currentIP"
'$currentIP'

No joy.

Thanks
You're right! Rechecked.
Previous test was not part of complete script.
Somehow $currentIP is empty!
Thanks
To clarify, even once I had confirmed that $currentIP contained the correct value, it still didn't work.
The solution that works is to define the IP as a constant each time the script is called.

eg
define("CURRENT_IP", $arrIPs[0]);
curl_setopt($ch, CURLOPT_INTERFACE, CURRENT_IP);