Solved

php best way to redirect

Posted on 2010-08-20
5
306 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
Comment Utility
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
Comment Utility
header('Location', 'http://.../index.php');
0
 
LVL 9

Expert Comment

by:jeremycrussell
Comment Utility
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
Comment Utility
What if I do not want to redirect right away and wait about 7 seconds?
0
 
LVL 9

Expert Comment

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

762 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

9 Experts available now in Live!

Get 1:1 Help Now