[RESOLVED] Header redirect
I currently have an order page that has three functions:
1. Displays the order with a submit button
2. Redirects to a payment page
3. Displays results of the payment
For step 2 - I want it to redirect to the payment page, but it won't because there is html code before the header code.
I have tried moving the redirect code to the top before html but it still doesn't work. It does work if I move the call to the functions there as well but this of course means that 1. and 3. display up the top, not in my html template.
Is anyone able to help me out on this? :) ... currently it just refreshes and shows nothing within the template rather then redirecting. If I echo out $url its all there... just doesn't redirect.
Heres a simple code example:
PHP Code:
<?php
//start the session and connect to db
session_start();
?>
<html>
<head>
<title>Page title</title>
<meta name="description" value="" />
</head>
<body>
<?php
//Functions
if (isset($_REQUEST["result"]))
{
# this is a redirection from the payments page.
print_result();
}
elseif (isset($_REQUEST["submit"]))
{
# this is a post back -- redirect to payments page.
redirect_form();
}
else
{
# this is a fresh request -- display order with a submit button
print_form();
}
?>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td>Logo</td>
</tr>
<tr>
<td>
<?php
function print_form()
{
//show order
}
function print_result()
{
//show payment successful or not successful message
}
function redirect_form()
{
//redirect to payment page
header("Location: ".$url);
exit;
}
?>
</td>
</tr>
</table>
</body>
</html>
Re: [RESOLVED] Header redirect
err. that will only work if you have a form action of something like "myscript.php?submit=yes," and you're submitting via POST. otherwise, the request_method would be POST and $_POST['submit'] would be the variable set.
also, if I'm understanding you correctly, you should have just been able to make the basic structure of your page like my first reply. the first redirect statement is at the top of the script, and the other two statements are found later on in the content.
either way, looks like you mostly have gotten it working now.