View Full Version : PHP return HTML source of a page?
rctxtreme
08-01-2007, 07:41 AM
Is there a PHP script which opens a page and returns its rendered HTML source (ie, must be able to return source of dynamic pages as well)?
Preferably, the script should also save the contents of the source into a file (of course, blanking it first if it already exists), of course I can do that myself.
If that has limitations, I'll just mention I wish to get the source of a page on the same website as the script.
For PHP? Sure:
ob_start();
include('file.php');
$page = ob_get_contents();
ob_end_clean();No limitations, but make sure 'file.php' is what you expect it to be -- remember that code is being run on your server.
rctxtreme
08-01-2007, 10:35 PM
I'll just add after rendering... somewhat like PHProxy, since that has to copy source, and happily works with any page.
HTML source
If you read it in like a normal file via an HTTP URL, it will be executed on the original server. However, this requires allow_url_fopen to be enabled. You can also accomplish the same thing by using curl, or by writing a basic HTTP client using fsockopen.
rctxtreme
08-02-2007, 10:59 AM
I tried the example for fsockopen on php.net, but it can only show the home page for a domain...
If you think that, you've vastly misunderstood the documentation. It is a raw socket, and can perform any HTTP transaction for which you care to use it.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.