Solved

php best way to redirect

Posted on 2010-08-20
5
313 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
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…

770 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