December 26th, 2012, 03:30 PM
Include a files Class or Data without displaying the page.
Wanted to see if anyone has a solution for my problem off the top of their head.
We have a set of pages for our system that are autogenerated by a program. (PHP Report Maker). These php pages contain both html and php. We have another section of the website where we post quick data based on the PHP Report Maker program. The solution we have in place right now is to copy the class out of the file. I would like to be able to some how include the file, or scrape the page instead of copying the class over so that changes are automatically handeled. I can't just use file_get_content because the site requires a log in. I am pretty sure it can be done with cURL, but the solution is likely to be over complicated for what we are doing and my supervisor won't accept the code. Another solution could be to use ob to caputre the output from the page and throw it away, but that isn't really a very eloquent solution and again is likely to be rejected by my supervision.
Is there a simple obvious solution I am missing?
December 26th, 2012, 04:01 PM
I think your explanation is a bit confusing as it relates to the title. You use 'include' or 'require' for PHP code and nothing is output until you have PHP output it. On the other hand 'file_get_contents' is used for reading HTML (as well as other non-PHP things) with PHP. In your case, if I understand, you don't have to worry about non-log users since you can locate the HTML and included PHP files in a private directory. The public PHP code is what would handle authentication then load the include files and output what ever HTML you want from the private directory or directories. The user running HTTPD would be the only one that needs read access to it.
There are 10 kinds of people in the world. Those that understand binary and those that don't.
December 26th, 2012, 05:41 PM
Please, don't get it twisted. You should be able to use : include() or require() to call your class, html or even php page on the fly without disclosing the page.
Go on top of the page you want to call the class or html document and type:
Comments on this post
December 26th, 2012, 06:38 PM
There is no way to include another PHP file without executing all of the code in it. In other words, if you have a PHP file that contains a mixture of PHP functions, classes and in-line code you can't include the functions and classes without executing the in-line code too. Using output buffering and then just discarding the output is really the only way you could do this; of course, that assumes that the in-line code doesn't change the state of the data at all.
Neither file_get_contents nor cURL can be used to include PHP functions or classes from another file.
You could write a script that modifies the generated output and then run that afterwords to get just the code you want to keep from it.
January 2nd, 2013, 06:53 AM
Sorry I didn't completely make clear that I need either the class, or the generated output after variable are passed in. So include doesn't work since it executes the page, but without the proper post/get variable being set. I have a couple of ideas now, and I will post back for postarity if something presents itself as a clear answer.
Originally Posted by E-Oreo
January 2nd, 2013, 05:53 PM
You can set $_GET and $_POST manually before including the file.
January 3rd, 2013, 12:42 PM
Silly me, see that was the obvious answer I new was out there. Ultimately this isn't going to work either. After having put some thought into it. The variables are just as likely to change as the SQL.
Originally Posted by E-Oreo
I think what I will do is suggest we write a puppet script that auto-generates the new class file from the PHPReportMaker file each time we puppet (which is how we distribute new content/changes anyway)
Thanks for being my sounding board.