Jump to content

opening url


lightray

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 = "http://68.178.234.207/";                                          // this works ok with fopen
//$filename = "http://68.178.234.207";
//$filename = "http://68.178.234.207/welcome.html";                        // this works ok with fopen
//$filename = "ftp://68.178.234.207/welcome.html";
//$filename =  "http://65.206.60.120/data/current_obs/KLFK.rss";
//$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
Link to comment
Share on other sites

http://ca.php.net/manual/en/function.file-get-contents.php

[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.
Link to comment
Share on other sites

This:

[code]<?php

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

?>[/code]

Outputs this:

[code]
<!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>
[/code]

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.
Link to comment
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 = "http://68.178.234.207/welcome.html"; // 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

thanks
Link to comment
Share on other sites

  • 1 month later...
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
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.