Submit and return form a php script to main page after 5 seconds

Hi all,

I have a script for which I would like to submit a form to.  But what I would like to do is to process the script and print out a message lets say

echo "Thank you! You will now be returned to the main page";

Is there a way of doing this so that the script page is displayed for lets say 5 seconds and is then redirected back to the page from which it came.  Not to go back to the page rather to be sent to the url of the page.

Many thanks

pjcrooks2000
LVL 8
pjcrooks2000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Diablo84Commented:
First thing to tackle:

>> redirected back to the page from which it came

There are several approaches to this, the most convienient (but not the most reliable) is the http referer. This is perfect in every sense accept the fact that sometimes it wont be set, in these cases you can add a default page to load if it isn't set.

eg:

$referer = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : "http://domain.com/defaultpage.php";

Another approach is using sessions to track the page activity, on each page you shift the value of a current page variable into a previous page variable (if the first is set) and then assign the current page (using $_SERVER['PHP_SELF']) into the current page variable. This allows you to be able to obtain the last visited page (on your server only) to redirect to but seems a bit over complicated for this.

The last method is to append the current page to the query string in the form tag, eg:

<form method="post" action="page.php?ref=<?php echo $_SERVER['PHP_SELF']; ?>"> etc...

Then:

$referer = (isset($_GET['ref'])) ? $_GET['ref'] : "http://domain.com/defaultpage.php";

Again we have a default page incase the query string isn't set.


Then we have the actual redirect, usually for redirecting we use:

header("location: http://domain.com/page.php");
exit;

However this is instant, as you need the delay i would use the meta refresh html tag. (In this example i have also included the HTTP_REFERER redirect method):

<?php
//process data

$referer = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : "http://domain.com/defaultpage.php";
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="refresh" content="5;URL=<?php echo $referer; ?>">

</head>

<body>

Thank you message here

</body>
</html>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pjcrooks2000Author Commented:
Once again Diablo fantastic answer :)

I guess I will have more for you soon ;)

pjcrooks2000
0
Diablo84Commented:
no problem as always :)

If you ever have anything come up relating to something you've already asked feel free to post back in the same thread even if it's PAQ'd. Good luck with your code.

|)iablo
0
pjcrooks2000Author Commented:
Thanks DIablo your great :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.