Solved

How to use CURLOPT_INTERFACE to make requests via multiple IP addresses

Posted on 2010-08-30
4
2,912 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:oldmoondog
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
Gatherer_Hade earned 250 total points
ID: 33559254
Make sure the ip address matches one that is bound to one of your network cards.  

Also, print out or otherwise inspect the value of the $currentIP variable.  I suspect it does not contain what you think it does.

0
 

Author Comment

by:oldmoondog
ID: 33559314
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
0
 

Author Closing Comment

by:oldmoondog
ID: 33559593
You're right! Rechecked.
Previous test was not part of complete script.
Somehow $currentIP is empty!
Thanks
0
 

Author Comment

by:oldmoondog
ID: 33560125
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);
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question