tags:

views:

134

answers:

4

Hi, I am trying to load content from a remote URL in my php code. There are two restrictions:

  1. I need to use the dedicated server IP I have so the REMOTE_ADDR of the other server has to be my dedicated IP. This eliminates Curl because Curl uses a proxy to load the remote URL and the proxy changes the IP address which does not work.

  2. I need to load the data on my back-end using PHP. I do not wish to use Javascript for security reasons.

Are there any other solutions other then Curl?

Thank you

+1  A: 

You could probably use fopen for this.

ChristopheD
+1 Yup, and if fopen_url_wrappers isn't enabled, there's always the lower level socket functions.
middaparka
+3  A: 

What about file_get_contents($url)? Just note that some websites require a user-agent, so you'll have to set one with ini_set() before making the call.

Jonathan Sampson
+1  A: 

Have you tried file_get_contents

<?php
$homepage = file_get_contents('http://www.stackoverflow.com/');
echo $homepage;
?>
Yada
A: 

When using the stream api and a wrapper that utilizes the socket-wrapper you can set the bindto context parameter to accomplish (1) :

Used to specify the IP address (either IPv4 or IPv6) and/or the port number that PHP will use to access the network. The syntax is ip:port. Setting the IP or the port to 0 will let the system choose the IP and/or port.
$ctx = stream_context_create( array(
  'socket' => array(
    'bindto' => '192.168.0.107:0',
   )
));

$c= file_get_contents('http://php.net', 0, $ctx);
VolkerK
Using the 'bindto' property was the key to this problem. Thank you
Pawel