[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

php best way to redirect

Posted on 2010-08-20
5
Medium Priority
?
329 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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this article, we’ll look at how to deploy ProxySQL.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month20 days, 6 hours left to enroll

872 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