every week i should archive my main page(which is a php) on the server in html format.till now i did it manualy.daes anyone know a better way like a script for it?i want a scrip which calls my index.php file ,does the php functions ,and save the results in html format,any idea?

    [man]curl[/man]

    The basic idea would be this.

    Use curl to open the page and get the html into a variable.

    Then write that variable to the archived html file.

    It should be doable in under 30 lines of code and that includes the looping and recursion to get the whole site.

      Yeah those would work, however those would need to be placed in the original scripts. I was thinking he could write a little script that would spider and archive his own site and then run it as a cron job. Then if he ever needed to archive another site it would be a simple matter of moving the archiver script.

        I'd think for one page, it'd be easy enough to just open it with [man]file_get_contents[/man], then [man]fwrite[/man] it. Like a 4 line script...

          Originally posted by LordShryku
          I'd think for one page, it'd be easy enough to just open it with [man]file_get_contents[/man], then [man]fwrite[/man] it. Like a 4 line script...

          That would give him the php, he wants the html that's generated by the php when it executes.

            I did something like this once, (the html files were called index.number.html) I think this is how I did it:

            1. Connect to the webserver using something like [man]fsockopen/man

            2. Feed some simple request headers to that connection, requesting for your php document

            3. Assign the HTML you get back to a variable

            4. Check to see what the next "free" html file is (i.e. the lowest numbered html file that doesnt exist)

            5. Create the file and open it for writing

            6. Write the contents of the variable containing the HTML to the file

            7. Close all the connections, close the file etc
              [/list=1]

              Sorry it's not in PHP!

              Originally posted by drawmack
              That would give him the php, he wants the html that's generated by the php when it executes.

              Not if you fopen the URL

              # For the sake of non-arguement :p
              $page = file_get_contents('http://somesite.com/index.php');
              if(!empty($page)) {
                 $open = fopen('/path/to/backup.html', 'w+');
                 fwrite($open, $page);
                 fclose($open);
              }

                You could do it that way, or you could use my longer, harder and memory hungrier script.

                Lol - why didn't I think that :S

                Meh.

                  <?php
                  $ch = curl_init('http://www.example.com');
                  curl_setopt($ch,CURLOPT_HEADER,0);
                  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
                  $page = curl_exec($ch);
                  curl_close($ch);
                  $fh = fopen('filename.html','w');
                  fwrite($fh,$page);
                  ?>

                  Using curl give you a lot of control of behavior that you don't have with the other methods mentioned. Basically what CURL is intended for is anytime you want your script to act like a web browser. You can get and send cookies, you can submit post forms, etc.

                  For more information see [man]curl_setopt[/man]

                    Write a Reply...