Reputation: 5523
I want to read a PHP file located on the same server as the script. Yet, I want to read it as if it is from another server so that it views the HTML output of the file.
But when I read the file using file_get_contents()
I just get the PHP Code.
NOTE: if this helps, I`m printing the contents of the file to fckEditor.
Upvotes: 0
Views: 1007
Reputation: 4773
use curl
function get_web_page( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}
$x=get_web_page('http://yourserver/the_script.php');
echo $x["content"];
Upvotes: 2
Reputation: 15232
You don't need to read it, just include it using include()
, for example:
$includefile="path/to/file.php";
if (file_exists($includefile))
include($includefile);
EDIT:
if you need to assign the output to a variable, use ob_start()
and ob_get_clean()
ob_start();
include($includefile);
$out = ob_get_clean();
Looking at the FCKeditor site, you would use it like this:
$FCKeditor->Value = $out;
Upvotes: 0