Page 1 of 1

opening url

Posted: Thu Aug 03, 2006 7:46 pm
by lightray
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


this is probably a baby question, so sorry ahead of time.....

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 the url's below with little success (only three work).
My setting for allow_url_fopen is 'On' under local and master ini.

it's the last one in the list that i really want to use.

Code: Select all

//$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";
}

thanks


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Aug 03, 2006 8:06 pm
by LiveFree
Well you may want to put all those vars in an array like..

Code: Select all

$filename = array();

$filename[] = "url here";

   foreach ($filename as $url){
if (fopen($url, "r")){
echo file_get_contents($url)
}else{
die('File Cannot be Found');
}
}

Posted: Thu Aug 03, 2006 8:09 pm
by Ollie Saunders
but have used the fopen to simply see if the page/file is accessable
Not really necessary. file_get_contents will return false or null if it can't get access to it.

Posted: Thu Aug 03, 2006 8:16 pm
by lightray
thanks guys,

my problem is that the three below all point to the same place but only the first
opens the page the other two indicate that the page does not exist. why is there a difference
i don't understand


//$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";

thanks

Posted: Thu Aug 03, 2006 8:21 pm
by Ollie Saunders
You running this locally or on a remote server?

Posted: Thu Aug 03, 2006 8:25 pm
by lightray
hi ole,

at the moment i'm running it from home, but want to put it on a remote server when it's debuged

regards

Posted: Thu Aug 03, 2006 8:41 pm
by Ollie Saunders
Well then I ain't got no clue. Sorry.

Posted: Thu Aug 03, 2006 8:45 pm
by feyd
Your server may have issues with requesting DNS information on the names. I'd check with your host.

Posted: Thu Aug 03, 2006 8:49 pm
by Ollie Saunders
Your server may have issues with requesting DNS information on the names. I'd check with your host.
That's what I would have said if you were running this remotely.

Posted: Thu Aug 03, 2006 8:58 pm
by lightray
thanks for all your help,

shall keep looking..........