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
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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

I would like to figure out how to get the eval(); working. But this seems to have worked pretty well:

 

ob_start();
echo include('file/name/here.php');
ob_end_flush();

 

I am very thankful to all the suggestions! roopurt18, Thorpe, thank you greatly!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.