Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2004-11-21
4
Medium Priority
?
270 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:pjcrooks2000
  • 2
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
Diablo84 earned 2000 total points
ID: 12640802
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
 
LVL 8

Author Comment

by:pjcrooks2000
ID: 12640830
Once again Diablo fantastic answer :)

I guess I will have more for you soon ;)

pjcrooks2000
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12640848
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
 
LVL 8

Author Comment

by:pjcrooks2000
ID: 12640852
Thanks DIablo your great :)
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question