matfish Posted March 2, 2007 Share Posted March 2, 2007 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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 2, 2007 Share Posted March 2, 2007 <?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 Quote Link to comment Share on other sites More sharing options...
matfish Posted March 2, 2007 Author Share Posted March 2, 2007 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 Quote Link to comment Share on other sites More sharing options...
matfish Posted March 2, 2007 Author Share Posted March 2, 2007 $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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.