homepage Welcome to WebmasterWorld Guest from 54.167.138.53
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Include vs File Implode
Shawn Steele

10+ Year Member



 
Msg#: 3276899 posted 7:19 pm on Mar 9, 2007 (gmt 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:

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

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



 
Msg#: 3276899 posted 8:25 pm on Mar 9, 2007 (gmt 0)

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

cmarshall

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3276899 posted 8:27 pm on Mar 9, 2007 (gmt 0)

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

joelgreen

5+ Year Member



 
Msg#: 3276899 posted 6:10 pm on Mar 12, 2007 (gmt 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 ......
<?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]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved