I'm wondering the best way to go to a new page. I have a PHP document with a submit button. Once that button is pressed, it runs the php code on that page, creates some session variables, then I want it to go to the next page after this code is executed. I know with traditional submit buttons you simply have the form that's run being the next page, but how do I link it differently?
Asked
Active
Viewed 59 times
0
-
Are you looking for the [Location header](http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php)? – Pieter van den Ham Jun 30 '16 at 07:58
-
If you´re using a from action is the best option otherwise header http://php.net/manual/en/function.header.php – Jun 30 '16 at 07:59
-
`header('Location: nextPage.php');` before any HTML output. – mitkosoft Jun 30 '16 at 07:59
3 Answers
0
You can force redirect with successful headers like as below:
header("Location: second.php");

Volkan Metin
- 178
- 4
-
From what I've seen, the header needs to be put first, however I want some php code to run first THEN a redirect to happen. Is this possible? – MandyLB Jun 30 '16 at 08:27
-
@MandyLB, yes, is possible, the only requirement is to haven't any HTML output before `header()` call. – mitkosoft Jun 30 '16 at 08:41
0
In a well designed web application, there is no direct relation between the script and the page as the control script is the same for every page and simply shows the page needed based on what was selected or done.
There are many ways to implement this but a good starting point would be to look at MVC design.

Julie Pelletier
- 1,740
- 1
- 10
- 18
0
set the URL of new page on form action=''
to load the another script after submit the form.

Raj
- 32
- 2