Solved

php best way to redirect

Posted on 2010-08-20
5
310 Views
Last Modified: 2013-12-13
Hi,

I was wondering what the best way is to redirect a user after they have submitted a form. currently after submitting the form a user would have to sit at a blank php page.

I need it to redirect after some operations are performed.

whats the best way?

thanks.
0
Comment
Question by:Solutionabc
5 Comments
 
LVL 3

Accepted Solution

by:
meagain35 earned 500 total points
ID: 33487732
typically using the header() function is quick and easy.
<?php
if ($_POST) {
  [the code you have for handling the submit]
  ....
  ....
  //Ok done, lets move them on.
  header(Location: "http://somewhere_else_but_here");
}
?>
<html>
<body>
page content
</body>
</html>

This would be placed at the top of the page after all your post work is done.
0
 
LVL 13

Expert Comment

by:marchent
ID: 33487733
header('Location', 'http://.../index.php');
0
 
LVL 9

Expert Comment

by:jeremycrussell
ID: 33487795
You can also use http_redirect() which is more forgiving if you happen to send output out to the page before you redirect.

It is part of the http extension, but if you have pecl or pear installed, pretty simple to add.

http://us2.php.net/manual/en/function.http-redirect.php

pear install pecl_http

http extension included many other powerful functions as well.
0
 

Author Comment

by:Solutionabc
ID: 33488020
What if I do not want to redirect right away and wait about 7 seconds?
0
 
LVL 9

Expert Comment

by:jeremycrussell
ID: 33488055
PHP offers a "sleep()" function, i.e sleep(7).
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now