Jump to content


Photo

opening url


  • Please log in to reply
4 replies to this topic

#1 lightray

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 = "http://68.178.234.207/";                                          // this works ok with fopen
//$filename = "http://68.178.234.207";
//$filename = "http://68.178.234.20...welcome.html";                        // this works ok with fopen
//$filename = "ftp://68.178.234.207/welcome.html";
//$filename =  "http://65.206.60.120..._obs/KLFK.rss";
//$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

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

Posted 04 August 2006 - 12:43 AM

http://ca.php.net/ma...et-contents.php

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

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

Posted 04 August 2006 - 12:44 AM

This:

<?php

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

?>

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>  
</HEAD>  
<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. 
</NOFRAMES> 
</HTML>

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

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 = "http://68.178.234.20.../welcome.html"; // 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

thanks

#5 11Tami

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.

<?php
$filename =
http://www.website.com/;
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