JsusSalv Posted July 31, 2009 Share Posted July 31, 2009 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? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted July 31, 2009 Share Posted July 31, 2009 eval(), but it's dangerous. Quote Link to comment Share on other sites More sharing options...
JsusSalv Posted July 31, 2009 Author Share Posted July 31, 2009 Dangerous? I'm intrigued....how so? Ways to make it safe? Alternatives? Thanks for such a quick reply!!! Quote Link to comment Share on other sites More sharing options...
JsusSalv Posted July 31, 2009 Author Share Posted July 31, 2009 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. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted July 31, 2009 Share Posted July 31, 2009 Read the whole file and pass it into eval(). <?php $file = "/some/other/file.php"; eval( file_get_contents( $file ) ); ?> Quote Link to comment Share on other sites More sharing options...
JsusSalv Posted August 1, 2009 Author Share Posted August 1, 2009 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? Quote Link to comment Share on other sites More sharing options...
JsusSalv Posted August 1, 2009 Author Share Posted August 1, 2009 Tried the following but doesn't work as expected. if ($mime) { header('Content-type: '.$mime); echo eval(file_get_contents($file); } No errors are displayed. The PHP just doesn't parse at all. Any pointers? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted August 1, 2009 Share Posted August 1, 2009 echo eval(file_get_contents($file); You're missing a closing-paren before the semicolon. Quote Link to comment Share on other sites More sharing options...
JsusSalv Posted August 1, 2009 Author Share Posted August 1, 2009 echo eval(file_get_contents($file); You're missing a closing-paren before the semicolon. No, that was a mistake...the code looks like this: echo $file = file_get_contents(eval($file)); but it doesn't work. Quote Link to comment Share on other sites More sharing options...
trq Posted August 1, 2009 Share Posted August 1, 2009 Why don't you just include the file and be done with it? Quote Link to comment Share on other sites More sharing options...
JsusSalv Posted August 1, 2009 Author Share Posted August 1, 2009 Why don't you just include the file and be done with it? Dude, it's proxy...there's a purpose for this. But good suggestion Quote Link to comment Share on other sites More sharing options...
trq Posted August 1, 2009 Share Posted August 1, 2009 Still, I would be using.... ob_start(); include '/somefile.php'; echo ob_get_clean(); Quote Link to comment Share on other sites More sharing options...
JsusSalv Posted August 1, 2009 Author Share Posted August 1, 2009 Still, I would be using.... ob_start(); include '/somefile.php'; echo ob_get_clean(); That is probably the easiest idea I've seen!!!! Gonna try it now. Thanks Thorpe! Quote Link to comment Share on other sites More sharing options...
JsusSalv Posted August 1, 2009 Author Share Posted August 1, 2009 Well, it does transfer the contents of the file into the proxy file. But the CSS doesn't style anything, yet, I can see the code in the stylesheet. Hmmm.... Quote Link to comment Share on other sites More sharing options...
JsusSalv Posted August 1, 2009 Author Share Posted August 1, 2009 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! Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted August 1, 2009 Share Posted August 1, 2009 Heh, I must have brain damage today. include() is a better solution. /facepalm Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.