Jump to content

Recommended Posts

Posted

After a success form submission, I will display a message say

Data has been submitted. Please wait for 3 seconds for page redirection

I used php function sleep()

i.e.

echo "Data has been submitted. Please wait for 3 seconds for page redirection";

sleep(3);

$session->redirect("./");

However message had never been echoed. It just delay 3 seconds and follow a page redirection

Posted

In web development, never use PHP's sleep function (the few exceptions to this rule are not worth mentioning).

$session->redirect sets a location header and according status code. By its nature, the header is processed by the user agent before any content is displayed to the user. So you either redirect with a header or present content to the user.

You have two possibilities:

1. Do your form processing early in the page and either set a meta http-equiv="refresh" header with timeout and destination or let javascript redirect to the page like Fokke suggested

2. Use an intermediate confirmation page that uses a meta refresh header and to which you pass the success message and the final target (not much different from the first, but it's often easier to work around the problem of already included HTML headers this way)

Posted

You're basically coding this logic on the server:

- Put the string "…" in the response

- wait 3 seconds

- set redirect header for the response

- send response to the user

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...