Jump to content


opening url

  • Please log in to reply
4 replies to this topic

#1 lightray

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 August 2006 - 12:17 AM

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/Kingfi...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.greenembr.../welcome.html";
//$filename = "http://greenembrace..../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...._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

#2 AndyB

  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 04 August 2006 - 12:43 AM


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.

That might shed some light.
Legend has it that reading the manual never killed anyone.
My site

#3 Caesar

  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 04 August 2006 - 12:44 AM



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


Outputs this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<HTML>  <HEAD>  
<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.
PHP Ninja

#4 lightray

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 August 2006 - 12:53 AM

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..../welcome.html";
//$filename = "http://www.greenembr.../welcome.html";

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


#5 11Tami

  • Members
  • PipPipPip
  • Advanced Member
  • 329 posts

Posted 24 September 2006 - 10:03 PM

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

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users