Results 1 to 6 of 6

Thread: PHP return HTML source of a page?

  1. #1
    Join Date
    Apr 2006
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP return HTML source of a page?

    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.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    For PHP? Sure:
    Code:
    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Apr 2006
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'll just add after rendering... somewhat like PHProxy, since that has to copy source, and happily works with any page.

    HTML source

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Last edited by Twey; 08-01-2007 at 10:52 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Apr 2006
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I tried the example for fsockopen on php.net, but it can only show the home page for a domain...

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •