lightray Posted August 4, 2006 Share Posted August 4, 2006 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 https://forums.phpfreaks.com/topic/16502-opening-url/ Share on other sites More sharing options...
AndyB Posted August 4, 2006 Share Posted August 4, 2006 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 https://forums.phpfreaks.com/topic/16502-opening-url/#findComment-68901 Share on other sites More sharing options...
Caesar Posted August 4, 2006 Share Posted August 4, 2006 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 https://forums.phpfreaks.com/topic/16502-opening-url/#findComment-68902 Share on other sites More sharing options...
lightray Posted August 4, 2006 Author Share Posted August 4, 2006 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 understandthanks Link to comment https://forums.phpfreaks.com/topic/16502-opening-url/#findComment-68909 Share on other sites More sharing options...
11Tami Posted September 24, 2006 Share Posted September 24, 2006 Hey lightray did you get fopen working? I am having same problem. When I try this, I onlyget 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 https://forums.phpfreaks.com/topic/16502-opening-url/#findComment-97783 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.