How can I download a _rendered_ web page using PHP? - php

I know I can use something like file_get_contents to save a web page's source locally, and I know how to manipulate the text of it. But what if the web page has JavaScript that dynamically generates content? How can I download the fully rendered page source?

You need to pass the data through a rendering engine. The simplest option is to programmatically control a web browser. Libraries that will help you do that include Selenium and php-phantomjs.

Related

Is there any way to use a Joomla site into an app using PhoneGap?

I am new in PhoneGap,
I have a Joomla Site, I want to create a PhoneGap App using that Joomla site. so is this possible ? if yes than how can i implement it ?.
You can use. But you have to create web services for request and responses. Because Phonegap will not run PHP script. So you can create webservices to access Joomla functionality via JSON responses from your joomla. You can get the JSON data via jQuery in your phonegap app.
and someone said PGBuild will convert webpage into phonegap app. You can try it also.
I have succeeded creating an application as follows:
Design your Joomla page so it's responsive and renders correctly on your mobile;
Download the whole thing with wget
Edit all urls and make them point to the right (local-remote) locations.
I saved all css, images, js locally so the page would load even offline; then changed all the links so they point to the remote host;
All forms should point to the remote host;
Most modules and components were changed so after the initial display (local) they will load the updated info in the frame.
Popups won't be available, so you'll need heavy workarounds for facebook integration etc.
Also, if you plan to use any phonegap features, they will only be available if you load the library inside your downloaded page; this will force you to change all calls to ajax (no document.location.href calls are possible since you'll lose the phonegap javascript).
The first time you load the page from the server it will take forever to load. Ensure you have proper caching set up otherwise you'll just lose your customers.
My advice is to start with an ajax project at the very beginning, it will save you lots of headaches.
Keep in mind, if you plan to use iframes, forget it. They work lousily on iphones, and debugging is nearly impossible. Simply take your time to plan a real phone app in javascript & using Ajax for the calls.
You don't need any webservices in Joomla for loading content, simply use:
&tmpl=component
when you need the content of a module.
Additionally, for blogs and lists, Joomla makes RSS feeds available so you shouldn't need too much coding to achieve this.
I have limited myself to ajaxifying the modules, which makes caching more efficient on the server and the interfaces appear more dynamic.

How to access iframe in PHP Scriptable Web Browser

I am using PHP Scriptable Web Browser for downloading some data from
one web site and that website contains so many links https://www.xxxx.com/CWRWeb/ReportNav.do?rid=CHARGEBACK using this link i want to download the data this page contains one iframe when is access this page using my script i am able to get the that page contain but not able to get iframe content from that page
can any one guide me.
Thank you.

can I use an iframe to load a php website on ruby on rails framework?

I have a client who wishes to use our website as a plugin on his website. His website is being developed in Ruby on Rails. While our website is a PHP website. I was considering using iframes to load my website inside theirs. However I am unsure if this is possible as I have no clue about the Ruby framework.
Please help.
Thanks in advance.
Yes, you can. The HTML that is served to web browsers is independent of the web framework used on the server side. A browser will not be able to distinguish HTML generated by a PHP/Python/Rails web application if the generated HTML is same. For browsers, it's just HTML which it'll parse and display content accordingly.
In your client's Ruby on Rails site, you can have an iframe embedded like this
<iframe src="http://www.yourphpsite.com/php_page.php"></iframe>
Iframes are independent from the framework you are using since they are purely HTML and can show any page that the visitor have access to. It might not be the most elegant solution, but it will work fine.
Iframes are browser-side HTML elements and can include anything that can be pointed to by a URL, so yes. You can include a PHP website on a Rails website or a .NET site or a Java Site or a Python site or a whatever. Please understand the over all topology/landscape of what runs where and what exists where.

PHP: Stream PDF (make PDF accessible only from webpage)

I have a site built in PHP and we have some PHP pages that require logging in that produce links to PDFs. The problem is that those PDFs (which were copied out to Amazon Cloudfront) were indexed and available for searching.
What is the easiest way to stream an existing PDF to the browser, making it so that the user has to login to be able to see the document? I'm hoping that there is some simple Header code or something where I can say "load this file on the server that's not accessible on the web and output it as PDF".
Any thoughts/suggestions?
Thanks!
You can use htaccess (or similar) to redirect any requests for a .pdf document to a PHP script, passing the requested file name. The script can then validate the log-in credentials, and if the user is logged in it can then send PDF headers, fetch the PDF document (file_get_contents) and output the code.
You can either block access to files (as mentioned in the other answer) or (more cleverly, IMHO) you can pass the file through to the browser after checking credentials (or doing pretty much anything) in PHP. There are code examples and a discussion here: http://bytes.com/topic/php/answers/159354-pass-through-any-file

Show pdf file into browser without Adobe Reader

I need to open pdf file into browser without Adobe Reader. Is there any API with php which open PDF files into browser.
Regards
No.
PHP runs on the server. The only "browser API" it has access to is HTTP.
If you want to render a PDF on the client, then the client needs a PDF renderer. There are JavaScript PDF readers, but I can't comment on their cross-browser support or maturity.
You can use SWFTools to convert PDFs to Flash. But SWFTools default skins are not looking good at all, so you can check Flexpaper as a viewer.
In case you are going to make your own skin, then could be useful to read: SWFTools (pdf2swf) to properly work with Flex
Another solution is pdf.js (as Quentin point out), but AFAIR this script was not usable(back then, when I looked for) for PDFs with complex structures (complex gradients for example).
If you need to publish documents as "private" you should look at services as Issuu or you will have to protect files from downloading.
If you pdf files are put online and not restricted, you can try using Google Doc Viewer. It's a very nice way to put the Viewer in <iframe /> so that it can be combined with your web page.
https://docs.google.com/viewer
It is not feasible to view the PDF files without a viewer like Adobe Reader. If you just don't want to use Adobe Reader, you may try a PDF viewer plug in for web browser from some other company.
However, if you do not want to use a viewer at all and want to write/build your own viewer then a better option is to convert the PDF to scalable images and then show them on the web page using image tags. You can also create such a viewer using JavaScript.
Even you can find many already available JavaScript based viewers which can show those images.

Categories