My server has several IPs. I usually set them using Plesk.

How can I change the IP that my server is using for CURL or file(http://google.com) from my script?

so i want something like this:

setmyIP (1.2.3.4); // now the server will use this ip when connecting somewhere
culr (www.myserver.com) //my outgoing ip is 1.2.3.4 when i access myserver.com

Thanks!
Alex

    I don't think that you can. You might be able to do it if you used sockets by binding to a specific interface.

    This would be a very bad idea because it would tie your app to a given IP address.

    Generally you shouldn't care.

    If you're using a service which authenticates by IP address, just add all of your server's IPs to it.

    Mark

      a month later

      I found a way to do this in php5:

      $conn = stream_context_create(array('socket'=>array('bindto' => "1.2.3.4:0")));
      $s = file_get_contents("http://phpbuilder.com/", NULL, $conn);

      i wish curl could use that $conn stream though

        a month later

        Yes you can bind CURL to a specific interface.

        To do this, set CURL's CURLOPT_INTERFACE option.

        See the php manual for this option.

          Write a Reply...