Jump to content


This topic is now archived and is closed to further replies.


opening url

Recommended Posts

I'm having trouble opening a URL. I wish to use the file_get_contents function, but have used the fopen to simply see if the page/file is accessable. I have tried all below with little success (only three work).

My setting for allow_url_fopen is 'On' under local and master ini.

//$filename = "http://pulsar/Kingfisher/Greenembrace/development/testfile.php";    // this works ok with fopen on my own server
//$filename = "file:///pulsar/Kingfisher/Greenembrace/development/testfile.php";
//$filename = "/Kingfisher/Greenembrace/development/testfile.php";
//$filename = "X:/Kingfisher/Greenembrace/development/testfile.php";
//$filename = "X:\Kingfisher\Greenembrace\development\\testfile.php";
//$filename = "Kingfisher/Greenembrace/development/testfile.php";
//$filename = "http://www.greenembrace.org/welcome.html";
//$filename = "http://greenembrace.org/welcome.html";
//$filename = "http://www.greenembrace.org/";
//$filename = "http://www.greenembrace.org";
//$filename = "http://greenembrace.org/";
//$filename = "ftp://www.greenembrace.org/welcome.html";
//$filename = "ftp://www.greenembrace.org/";
//$filename = "";                                          // this works ok with fopen
//$filename = "";
//$filename = "";                        // this works ok with fopen
//$filename = "";
//$filename =  "";
//$filename =  "http://www.nws.noaa.gov/data/current_obs/KLFK.rss";

if (fopen($filename,"r")) {
  echo "The file $filename exists";
echo file_get_contents($filename);
} else {
  echo "The file $filename does not exist";

please direct me

Share this post

Link to post
Share on other sites

[quote]Tip: You can use a URL as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename and Appendix M for a list of supported URL protocols.[/quote]

That might shed some light.

Share this post

Link to post
Share on other sites


$test = file_get_contents("http://www.greenembrace.org/testfile.php");


Outputs this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1"> 
<TITLE>The Green Embrace</TITLE> 
<FRAMESET cols = "130,*" frameborder=yes bordercolor=silver name="full">  <frame src="links.php" name="links" scrolling="No">  <frame src="home.php" name="main" scrolling="AUTO">  </FRAMESET>  <NOFRAMES>  Your Browser does not seem to support Frames - <a href="./index.php">- Click Here -</a> - to Continue.

Note that one can disallow the "file_get_contents" function on a server. I have seen it done in the past. Infact, it is disabled in a free hosting account I use.

Share this post

Link to post
Share on other sites
thanks AndyB, i have read the manual page many times and followed the links without much luck.
thanks also Caesar.

//$filename = ""; // this works ok with fopen
//$filename = "http://greenembrace.org/welcome.html";
//$filename = "http://www.greenembrace.org/welcome.html";

these three point to the same place but only the first works!
i don't understand


Share this post

Link to post
Share on other sites
Hey lightray did you get fopen working? I am having same problem. When I try this, I only
get a blank page and no error message, almost like its working but not showing the url.

$filename =
fopen($filename, "r") || die ("Could not open file");


Does someone know whats wrong with fopen retrieving url's? Thanks

Share this post

Link to post
Share on other sites


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.