Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Include vs File Implode

7:19 pm on Mar 9, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 5, 2003
votes: 0

What is the most efficient way of including a file inside of another file with considerations of server load, page loading time, etc? For instance, lets say I want to include the search results on an example page. So in example.php something like:



echo implode("",file("http://www.domain.com/search.php?x=1&y=2"));

So which of these is better, or alternatively, is there a better, faster option?


8:25 pm on Mar 9, 2007 (gmt 0)


WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
votes: 2

file_get_contents [php.net] will allow you to retrieve it as an entire string.
8:27 pm on Mar 9, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2005
posts: 1526
votes: 0

There's also readfile() [us2.php.net]. That outputs the file directly to standard output.
6:10 pm on Mar 12, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:July 31, 2006
votes: 0

I would not use include here because of security reasons.
As you might know include function will try to parse php code inside the file.

Lets say http://www.example.com/search.php?x=1&y=2 has following content:

Here is some text ......
echo "You've been just hacked".

it would execute php code on your server.

So better use file,file_get_contents, or readfile :)

[edited by: jatar_k at 7:43 pm (utc) on Mar. 12, 2007]
[edit reason] please use example.com [/edit]


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members