Jump to content

Includes - but different servers


matfish

Recommended Posts

Hi,

 

How can I include a .php file which is located on a different server/host?

 

include_once("http://www.domain.com/dir/include_this.php");

 

The above gives: failed to open stream: Connection refused in...blah blah

 

Trying to use one file over several sites

Link to comment
Share on other sites

<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
   echo "$errstr ($errno)<br />\n";
} else {
   $out = "GET / HTTP/1.1\r\n";
   $out .= "Host: www.example.com\r\n";
   $out .= "Connection: Close\r\n\r\n";

   fwrite($fp, $out);
   while (!feof($fp)) {
       echo fgets($fp, 128);
   }
   fclose($fp);
}
?> 

 

 

http://uk.php.net/fsockopen

 

Link to comment
Share on other sites

Hi, thanks for the reply.

 

I get:

 

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in [location of file] on line 17

 

Warning: fsockopen() [function.fsockopen]: unable to connect to [file location].php:80 in [header location] on line 17

Success (0)

 

 

You think my hosts may not be allowing the connection?

 

Thanks again

Link to comment
Share on other sites

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://www.domain.com/dir/include_file.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;

 

the above doesnt work either but doesnt show any errors, does this mean curl is not installed on the host? Will take a week to get a reply from them!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.