Include a files Class or Data without displaying the page.
Discuss Include a files Class or Data without displaying the page. in the PHP Development forum on Dev Shed. Include a files Class or Data without displaying the page. PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 60
Time spent in forums: 1 Day 58 m 28 sec
Reputation Power: 8
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.
Posts: 2,885
Time spent in forums: 1 Year 2 Weeks 3 Days 8 h 17 m 9 sec
Reputation Power: 581
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.
Posts: 7
Time spent in forums: 24 m 28 sec
Reputation Power: 0
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:
Posts: 7,944
Time spent in forums: 2 Months 10 h 16 m 54 sec
Reputation Power: 7053
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.
Posts: 60
Time spent in forums: 1 Day 58 m 28 sec
Reputation Power: 8
Quote:
Originally Posted by E-Oreo
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.
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.
Posts: 60
Time spent in forums: 1 Day 58 m 28 sec
Reputation Power: 8
Quote:
Originally Posted by E-Oreo
You can set $_GET and $_POST manually before including the file.
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.
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)