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? Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/ Share on other sites More sharing options...
roopurt18 Posted July 31, 2009 Share Posted July 31, 2009 eval(), but it's dangerous. Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-887960 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!!! Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-887962 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. Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-887997 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 ) ); ?> Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-888007 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? Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-888021 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? Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-888023 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. Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-888063 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. Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-888066 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? Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-888068 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 Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-888071 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(); Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-888073 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! Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-888076 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.... Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-888077 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! Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-888083 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 Link to comment https://forums.phpfreaks.com/topic/168333-solved-parse-php-before-using-fopen/#findComment-888169 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.