Jump to content

[SOLVED] Parse PHP before using fopen()


JsusSalv

Recommended Posts

Hello:

 

I'm using a proxy script and it works well. However, the information I'm grabbing from the real file contains PHP code and it isn't parsed beforing display the contents on screen. Is there a way to parse PHP code from a file before using fopen() to read its contents?

 

Here's the code for the proxy script

 

$file = 'some file...';
$mime = 'text/css'

if ($mime) {
header('Content-type: '.$mime);
$file = @ fopen($file, 'r');
if ($file) {
	fpassthru($file);
	exit;
}
}

 

The $file has a bunch of css and a few PHP code blocks. How can I get the code blocks to parse/retrieve db info before being spit out to the screen?

 

Would file_get_contents work better?

Link to comment
https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/
Share on other sites

I was reading through the php.net manual for eval():

 

http://us2.php.net/manual/en/function.eval.php

 

So, with my code, would I add the eval() before or after fopen()? It makes more sense to use it after reading the file but I just want some ideas/opinions.

Read the whole file and pass it into eval().

 

<?php
$file = "/some/other/file.php";
eval( file_get_contents( $file ) );
?>

 

 

Like this:

 

$file = "/some/other/file.php";
$mime = 'text/css'

if ($mime) {
   header('Content-type: '.$mime);
   echo eval( file_get_contents( $file ) );
}

 

Or how should I rewrite my code?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.