How to use CURLOPT_INTERFACE to make requests via multiple IP addresses

Posted on 2010-08-30
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, "");

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 ( it fails.

Any suggestions?

Question by:oldmoondog
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Accepted Solution

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.


Author Comment

ID: 33559314

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, "");

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

No joy.


Author Closing Comment

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

Author Comment

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.

define("CURRENT_IP", $arrIPs[0]);

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Apache LDAP Authentication 20 53
Why is PHP Storm giving me an undefined constant error? 4 36
Make login page safer 3 32
Echo'd values in dropdowns 6 29
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
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.

756 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