Welcome to WebmasterWorld Guest from 220.127.116.11 , register , free tools , login , search , pro membership , help , library , announcements , recent posts , open posts Become a Pro Member
Include vs File Implode Shawn Steele msg:3276901 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:
So which of these is better, or alternatively, is there a better, faster option?
coopster msg:3276966 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 msg:3276970 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 msg:3279652 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]