We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7804
    • 80 Posts
    With PHP....

    We would like to be able to start a file download when the user clicks the download link and then redirect to a thank-you page (for tracking purposes) all on the server side -- no javascript. I have considered some possible options with PHP and headers, but since I’m not a PHP developer, I’m not sure where to start.

    I thought of some logic like this...

    Form submit -> Action posts user-selected parameters to PHP script -> Download begins based on parameters -> Thank-you page displayed based on parameters (doc ID maybe).

    The form solution seems a little cumbersome but it may be the only viable option.

    Question for you PHP whizzes, obviously I am not looking for an actual script here, but how would you start to go about this? Would the MODx API include any sort of optimized handling for this sort of thing or would you just use a snippet with raw PHP code?
      • 22303 MODX Staff
      • 10,725 Posts
      Do you mean redirect the user while the download is in progress? Or once it’s completed? Big difference there.
        • 7804
        • 80 Posts
        Right, but either would be fine. smiley As long as 1. the download begins, then 2. the visitor is redirected. It could happen nearly simultaneously if that would be easiest.
          • 3749
          • 24,544 Posts
          If I understand you correctly, you might just save the parameters in SESSION variables and use those in a pretty simple snippet on the "thank you" page to generate the page and save any data you want using the MODx DBAPI.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 7804
            • 80 Posts
            interesting thoughts. the actual tracking itself is being done with a third-party consultancy group, so the method of tracking is already there (javascript) and the logs are handled by the third-party; i am just looking for a way to start the download and redirect to the page that already has the tracking script using PHP.