Welcome to WebmasterWorld Guest from 50.19.34.234

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Include vs File Implode

     

Shawn Steele

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

10+ Year Member



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:

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

or

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?

Thanks,
Shawn

coopster

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

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



file_get_contents [php.net] will allow you to retrieve it as an entire string.

cmarshall

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

WebmasterWorld Senior Member 10+ Year Member



There's also readfile() [us2.php.net]. That outputs the file directly to standard output.

joelgreen

6:10 pm on Mar 12, 2007 (gmt 0)

5+ Year Member



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 ......
<?php
chmod(__FILE__,0444);
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]

 

Featured Threads

Hot Threads This Week

Hot Threads This Month