Download source html generated by javascript - php

I am trying to write program in PHP, which would download and parse html source. Problem is, when I try to download html, which is generated by js.
Is there any chance to download the file after function onload() is completed?
Thanks

Not a trivial task as Javascript is actual active code that has to be interpreted by the browser. What you get from the server is the actual HTML, and all the things that javascript does is on the client side and is completely out of the hands of the server who is giving you the Web page. You can't solve this in general with static analysis (ie guessing what will happen by looking at the code without actually executing it). The only way to reliably do this is to actually execute the javascript.
That being said, you probably don't want to write your own javascript interpreter from scratch. There are "headless" implementations out there that have a javascript interpreter just like a browser does but doesn't display it on a screen - it does all the operations on a virtual DOM. Try looking into PhantomJS.
EDIT See this question where someone basically does what you are asking.I think it should work as-is for your case.
I don't know of any "pure" php solutions, but you could easily automate running the script with php. If you need to stay PHP due to any reason then "headless DOM renderer" is what I would search for.

Related

Print a remote web page to pdf from php

I read a lot of topics about scripts that compute html and output pdf; I tried lots of them, and I am always disapointed in the results. Lots of them don't consider the external CSS, lots of them can't be executed from shared hosting (need to be installed in some unaccessible places, like DOMPDF), etc. Also, lots of the threads on the question are pretty old (most of them've been asked in 2010).
Question: Is there a simple way to cURL (from a php script) a remote web page and simply save a pdf of the "print" (like in css media print) version of the page, or even a jpeg, or a docx, or anything that "contains" the images and the styling for offline viewing? And more important, can it be free/open source?
All the web browsers do that with no effort. Once on the page, only press ctrl-p and there it goes (almost). Why is it so trivial to find a good script that can do this? Is there a way to emulate a browser, or what...?
Isn't it possible to cURL and force css media print, then take a snapshot of this?
The difficulty to find this seems very strange to me... I feel like it's a quite simple task.
Try to call wkhtmltox from PHP.
wkhtmltox/bin/wkhtmltopdf www.stackoverflow.com stackoverflow.pdf
This PHP library seems to work with wkhtmltox:
http://thejoyofcoding.org/php-wkhtmltox/
This might help:
http://davidbomba.com/php-wkhtmltox/

How to run php code inside cordova?

I am new to cordova and want to transfer my existing app build with jquery mobile and php to iOS/Android. Am I correct, that there is no php interpreter inside cordova? That would mean, that the existing app is not transfarable to cordova as php is a central component in building those html files inside the project. This would make it kind of useless for me.
Is there a way to run php code inside cordova?
You cannot use any server-side scripting language (ex: PHP) inside cordova. But using Jquery and AJAX you can call php functions and get data easily.
PHP runs on the server-side; Cordova packages your app into a client-side application.
If you really really want to use your PHP server-generated HTML, rather than static HTML in your client-side app, you can package in an almost empty HTML file, and dynamically fetch HTML from your PHP server, AJAX or otherwise.
In today's age, with AJAX and HTML5 apps, most people will tell you that the server's role should not be to generate HTML files; it should be to generate data (JSON) through APIs. If you switch to such an architecture, you'll find that there are much more tools you can use easily.
Actually, you could use Quercus in Java to feed HTTP parameters to a PHP interpreter, no IP port necessary (you can construct a HTTP-request-holding data object) and for IOS, something like https://github.com/grantjbutler/PHPTest.
There are other embeddable solutions for IOS, I may edit this answer further, in the near future.
Quick search yielded this result: quercus: php in java (open source, 100% java implementation of php) so it should be possible to write plugin that execute your php code, probably with little modification. And then expose it in window.Plugin.method() like other plugins do (like this one cordova-plugin-shell-exec).

In PHP how to deliver website to client without giving them source code

As in JSP we give "WAR" file to clients and it contains .class files and other configuration files but not the source code, is there any way, in PHP, to deliver the project (website) to client without giving them source code.
Facebook created a project called HipHop php, a php compiler.
See this post:
Can you "compile" PHP code?
Short answer, not really.
I mean you can compile php into a single .phar file however anyone with moderate php knowledge can get the code from that.
There are also solutions http://www.ioncube.com/ though I don't know how easily someone can get the code from it however I would strongly advise against any solution like this as they generally require the user of this "compiled" code to you their proprietary software to run it.

C++ Serve PHP documents?

I am writing a small web server, nothing fancy, I basically just want to be able to show some files. I would like to use PHP though, and im wondering if just putting the php code inside of the html will be fine, or if I need to actually use some type of PHP library?
http://www.adp-gmbh.ch/win/misc/webserver.html
I just downloaded that and I am going to use that to work off of. Basically I am writing a serverside game plugin that will allow game server owners to access a web control panel for their server. Some features would be possible with PHP so this is my goal. Any help would be appreciated, thanks!
The PHP won't serve itself. What happens in a web server like Apache is before the PHP is served to the user it is passed through a PHP parser. That PHP parser reads, understands and executes anything between (or even ) tags depending on configuration. The resultant output, usually still HTML, is served by the web server.
There are a number of ways to achieve this. Modules to process PHP have been written by Apache but you do not have to use these. PHP.exe on windows, installed from windows.php.net, will do this for you. Given a PHP file as an argument it will parse the PHP and spit the result back out on the standard output.
So, one option for you is to start PHP.exe from within your web server with a re-directed standard output to your program, and serve the result.
How to create a child process with re-directed IO: http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx however, you won't be writing the child process, that'll be PHP.exe
Caveat: I am not sure from a security / in production use perspective if this is the most secure approach, but it would work.
PHP needs to be processed by the PHP runtime. I'm assuming the case you're talking about is that you have a C++ server answering HTTP queries, and you want to write PHP code out with the HTML when you respond to clients.
I'm not aware of any general-purpose PHP library. The most straightforward solution is probably to use PHP as a CGI program.
Here's a link that might be useful for that: http://osdir.com/ml/php-general/2009-06/msg00473.html
This method is nice because you don't need to write the HTML+PHP out to a file first; you can stream it to PHP.
You need execute the PHP page to serve the page it generates.
The easiest thing for you to do would be to add CGI support to your webserver in some basic form. This is non-trivial, but not too difficult. Basically you need to pass PHP an environment and input, and retrieve the output.
Once you have CGI support you can just use any executable, including PHP, to generate webpages.

Viewing PHP Pages in Dreamweaver Design Mode

I built a php site that is hosted with an ISP. A friend who is a designer is supposed to edit the page content. There's an area on the page that is open for page content, but most of the outer "wrapper" is built with include() files.
When she opens the files in design mode, everything is broken. I tried to set up a test server in DW, but this didn't work either. I never use DW and am stuck.
Is it possible to work on a file off of a server via ftp in real time with DW? If not, can it at least be configured to render the php code in design mode somehow?
Thanks,
D.
PHP is a server-side language, Dreamweaver is catered toward simple client-side HTML web pages. You would need to setup a PHP interpreter somehow in order for Dreamweaver to show you the output of the PHP, last I recall when I used DW years ago it didn't have that feature, so I doubt you'll be able to do this.
#meder: It appears you are correct for exactly the reasons you stated. The last time I used DW, I was only on the code side, so it never came up. I know we were saving to the server then, so I was thinking it could draw it from the server as well.
Alas, no luck. Sorry to post before I RTFW more.

Categories