PHP: Direct to another HTML page?

Appledrop

Platinum Member
Aug 25, 2004
2,340
0
0
heh, all in titles really, ive attached the php code (i think?).
when the user presses submit on my first html page, and it runs the php script, i want it to display a different HTML file..

thanks
 

Modeps

Lifer
Oct 24, 2000
17,254
44
91
Why not just post to another page in your form?

<form action="newpage.php" method="post">
<input...
</form>
 

mugs

Lifer
Apr 29, 2003
48,920
46
91
Header("Location: otherPage.php");

I use that because I like to keep validation/processing pages separate from entry/navigation pages.
 

Beau

Lifer
Jun 25, 2001
17,730
0
76
www.beauscott.com
Originally posted by: mugs
Header("Location: otherPage.php");

I use that because I like to keep validation/processing pages separate from entry/navigation pages.

Actually, PHP buffers it's output and headers, so by simply calling header('Location: myloc.php'); your script could execute unexpected code.

so, do this:

header("Location: otherpage.php");
exit;

Also, according to HTTP/1.1 standards, when you send a Location header, you're supposed to send a full, absolute URL (including the HTTP), so in reality you'd want to do something like:

header("Location: http://myserver.com/myscript.php");
exit;

I actually use a function that determines what kinds of url you're trying to redirect to (local absolute, local relative, or remote) and formats an absolute URI, then redirects to it. I've attached to code snippet so you can see/use it. It can also handle querystrings on the end of the addresses, and encodes them correctly.

Usage:

// Local Relative
Redirect('../myurl.php');
or
Redirect('myurl.php');

// Local Absolute
Redirect('/myurl.php');

// Remote
Redirect("http://www.myurl.com/")
 

mugs

Lifer
Apr 29, 2003
48,920
46
91
Originally posted by: Beau
Originally posted by: mugs
Header("Location: otherPage.php");

I use that because I like to keep validation/processing pages separate from entry/navigation pages.

Actually, PHP buffers it's output and headers, so by simply calling header('Location: myloc.php'); your script could execute unexpected code.

so, do this:

header("Location: otherpage.php");
exit;

I prefer not to have exit points scattered throughout a page, so I usually put the redirect at the end of the page and use conditionals if I want to prevent some code from executing.