oldmoondog
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
However, I want to pass in the relevant IP dynamically. When I try in the form:
Where $currentIP contains the IP address (xxx.xxx.xxx.xxx) it fails.
Any suggestions?
Thanks
curl_setopt($ch, CURLOPT_INTERFACE, "xxx.xxx.xxx.xxx");
However, I want to pass in the relevant IP dynamically. When I try in the form:
curl_setopt($ch, CURLOPT_INTERFACE, $currentIP);
Where $currentIP contains the IP address (xxx.xxx.xxx.xxx) it fails.
Any suggestions?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You're right! Rechecked.
Previous test was not part of complete script.
Somehow $currentIP is empty!
Thanks
Previous test was not part of complete script.
Somehow $currentIP is empty!
Thanks
ASKER
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);
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);
ASKER
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