save php page into html automatically

Discussion in 'PHP' started by master-mind, Oct 18, 2009.

  1. #1
    Hello,

    I am having a problem and tired finding a solution on Google.

    Here is the scenario.
    I have a php shopping cart and the cart after final checkout, generates an invoice. The invoice layout and page has been created in php. for example.

    domain.com/invoice.php?cid=xxx&sid=xxx

    Now this page serves perfectly fine in my browsers like I want with all purchase details of the customer. This invoice.php page is actually an exact printable invoice with just a company logo and CSS and html table layout. No extra images or something.

    All I need, is that when the invoice.php is executed, it should have a php code which should save the same invoice output as .html file on the ftp folder.

    Thanks.
     
    master-mind, Oct 18, 2009 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The simplest way would be to create a special url where you specify the same details as you are, but a security key as well, and then call the url using file_get_contents('http://www.yourdomain.com/file.php?sid=12345&cid=12345&passcode=blahblah"); then save the file using the file_put_contents function
     
    JAY6390, Oct 18, 2009 IP
  3. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #3
    One way to do it would be to use ob_start() before the page is output to turn on output buffering and
    
    $page = ob_get_contents(); //capture buffered output
    file_put_contents("filename",$page); //save it
    ob_end_flush(); //display it to end user
    
    PHP:
     
    Gray Fox, Oct 18, 2009 IP
  4. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #4
    I agree with Gray_Fox's solution because at times contents are not simply received through url calls, but through post methods and curl outputs. However, if url is called simply using get parameter's JAY6390 has already suggested a good method. Try both the methods and use best suitable for you :)
     
    mastermunj, Oct 18, 2009 IP
  5. master-mind

    master-mind Well-Known Member

    Messages:
    91
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    111
    #5
    well, I tried this too. but it does not execute php in the file contents. it shows its code as html.

    I some how sorted that issue. But now I am looking for another solution.

    When the invoice page loads, it generates a PDF and attaches and emails the PDf invoice to the customer. the problem is, PDF generation takes time, like 1 or 2 minutes, but the email sending code below it executes at the same time and as a result, it sends a PDf file with 0KB, because when the email function executed, the PDF was not completely generated.

    Is there a way to code php with some time frame? like after page load, email function should be execute after 5 minutes?

    thanks for the help
     
    master-mind, Oct 19, 2009 IP
  6. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    So you wanted to save the page with the PHP code still unexecuted in it? what exactly would be the point in that?
     
    JAY6390, Oct 19, 2009 IP
  7. master-mind

    master-mind Well-Known Member

    Messages:
    91
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    111
    #7
    no, I do not want to save the php page anymore I have sorted that already.

    I need to know about the php code to be executed after a specific number of minutes or seconds.

    thanks
     
    master-mind, Oct 19, 2009 IP
  8. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I see. You could just use the sleep() function before your mail() function and set it to say 3 minutes so that the script delays for 3 minutes before sending.
    Another solution would be to check the file size of the file in a do while loop until it's not 0KB. Other than that, the only other solution I can suggest is to have a db table log the time the pdf starts generating and then have a cron job run your mail script for every file that's been generated say 5 minutes ago or more that hasn't been sent
     
    JAY6390, Oct 19, 2009 IP
  9. Bhavik77

    Bhavik77 Greenhorn

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #9
    hi master-mind.. can you tell me how did u executed php and stored in html as i am trying for same
     
    Bhavik77, Feb 15, 2014 IP