Page 1 of 1
Does this include files using echo file_get_contents
Posted: Wed Apr 13, 2011 11:28 pm
by Stosh
Hi,
I'm guessing this answer is out there, but I'm stumped on how to search it.
My hosting service would like to upgrade me. They say they'd prefer for PHP scripts to include files like this:
Code: Select all
<? echo file_get_contents("http://example.com/somefile.html"); ?>
They say they would allow me to add support for the "other" kind of includes but didn't sound like they really wanted to do that. I.e.,
Code: Select all
<? include "http://example.com/somefile.html" ?>
Which way does your script work? Is there a setting for this, or will I just have to do this in their "not recommended" way (that would be, set a switch in the htaccess file).
Thanks for your help.
-s
Re: Does this include files using echo file_get_contents
Posted: Thu Apr 14, 2011 9:29 am
by Timbalu
Well you need both, which are different in use. With include() you can include other PHP files or classes to your framework. You would never use it for a normal html file to fetch its content. In this first meaning, this is used often here. And file_get_contents() will read the contents of a file into a string, like the file() command does similar. This is used somewhere too, at least in smarty.
So your hoster sound a little bit GAGA when offering just one of these.
Re: Does this include files using echo file_get_contents
Posted: Thu Apr 14, 2011 10:13 pm
by kleinerChemiker
You can use include() to fetch external data. I think Stosh only is worried about including external data. I don't know every line of s9y, but since useing include() for external data is bad coding, I think file_get_content() or fopen() is normaly used.
Re: Does this include files using echo file_get_contents
Posted: Wed Apr 20, 2011 8:31 pm
by Stosh
Thanks guys.
Not being a regular PHP coder I'm not sure what this means. I'm guessing they are simply trying to avoid making an HTTP request through the server when including PHP code/data? Just a speculation like I say.
They let me add the necessary flag for both by adjusting my ht file, and really only recommend it. . .
If you use both, I think they will be fine with this (should I decide to move this over there).
Thanks again.
-s
Re: Does this include files using echo file_get_contents
Posted: Thu Apr 21, 2011 10:48 am
by Timbalu
Well, as kleinerChemiker said, there wont be for sure no external data including via PHPs include() function.
<? include "
http://example.com/somefile.html" ?>