Solved

How to use CURLOPT_INTERFACE to make requests via multiple IP addresses

Posted on 2010-08-30
4
2,769 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
Comment Utility
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
Comment Utility
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
Comment Utility
You're right! Rechecked.
Previous test was not part of complete script.
Somehow $currentIP is empty!
Thanks
0
 

Author Comment

by:oldmoondog
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now