saifuddin778
saifuddin778

Reputation: 7277

Create a Loading page between two PHP pages

I have two PHP pages...page A and page B. Page A is basically a form that takes input values from a user and posts them to page B which runs a python script to do some calculations over the submitted values and presents the calculated values on page B. I want to include a page C in between A and B which displays a loading bar or icon meanwhile the page B's content is prepared to be displayed, and then directs user to the page B. Is there a pure PHP or PHP+JS+CSS way of doing this?

The idea is to capture the status of page B and the user is only directed to Page B from Page C when Page B's content is ready to be displayed.

Upvotes: 2

Views: 448

Answers (1)

Dave
Dave

Reputation: 46259

There are two possible ways to do something like this.

Both begin with AJAX; when you submit A.php it should send an AJAX request instead of loading B.php directly. A then has a chance to act on the response as it happens.

For communicating progress, here are your options:

  1. B.php prints to the output at regular intervals. This is easy, and used to be used in a few places for reporting file compression progress among other things. It isn't very reliable. Buffering means it will jump around and generally behave badly. This doesn't need AJAX, but will look ugly without it.
  2. B.php writes to a file at regular intervals, and D.php reads this file and returns the results. Now you make A.php send a request to D.php every couple of seconds (or whatever you need for good results) with a query parameter saying which request to check the progress of. This is much more reliable, but harder to set up.

Upvotes: 1

Related Questions