Does this include files using echo file_get_contents

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Stosh
Regular
Posts: 77
Joined: Mon Oct 12, 2009 11:47 pm

Does this include files using echo file_get_contents

Post 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
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Does this include files using echo file_get_contents

Post 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.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
kleinerChemiker
Regular
Posts: 765
Joined: Tue Oct 17, 2006 2:36 pm
Location: Vienna/Austria
Contact:

Re: Does this include files using echo file_get_contents

Post 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.
Stosh
Regular
Posts: 77
Joined: Mon Oct 12, 2009 11:47 pm

Re: Does this include files using echo file_get_contents

Post 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
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Does this include files using echo file_get_contents

Post 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" ?>
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Post Reply