Code Comments
Programming Forum and web based access to our favorite programming groups.Greetings, Jerry Stuckle. In reply to Your message dated Thursday, April 3, 2008, 02:32:32, > Good programmers fix errors. Sloppy programmers hide them with thinks > like ob_start(). It is not hiding and it is not an error. It is usage of proper tools the rig ht way to achieve given goals. I do not want to break program logic in the favor of Your "good programming" . Call it bad logic, but it is more clear, than Your goodness. So far. -- Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru>
Post Follow-up to this messageAnrDaemon wrote: > Greetings, Jerry Stuckle. > In reply to Your message dated Thursday, April 3, 2008, 02:32:32, > > > > It is not hiding and it is not an error. It is usage of proper tools the r ight > way to achieve given goals. > I do not want to break program logic in the favor of Your "good programmin g". > Call it bad logic, but it is more clear, than Your goodness. So far. > > It is an error, but you're too stoopid to understand that. But that also matches the rest of your posts here. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
Post Follow-up to this messageOn Mar 9, 2:09=A0pm, Sudhakar <sudhakarar...@gmail.com> wrote:
> i have a registration page which is a self submitting form <form
> action=3D"<?php echo $_SERVER["PHP_SELF"]; ?>" method=3D"POST"
>
> id=3D"test2" name=3D"registrationform">
>
> where in a user fill a form, after the data has been inserted to a
> database i would like to redirect the user to a different
>
> page. i am not able to use header(Location: filename.html) as i have
> echo statements before and i get a message that headers
>
> have already been sent. so due to this i am using
>
> echo (" <meta http-equiv=3D'refresh' content=3D'0;url=3Dthankyou.php?
> firstname=3D$firstname'> "); this works perfectly fine.
>
> however if a user disables meta refresh which is a very small
> possibility the above meta tag would not execute to avoid such
>
> a situation i would like to use echo statements to create a new page
> which would have html tags and display a similar page to
>
> thankyou.php
>
> in my case the php code is placed in the middle of the page which
> displays messages that a user did not enter in the form.
>
> the page is so structured that there is some information written using
> html tags followed by the registration questions where
>
> the php code is present to validate. i have used
>
> echo (" <meta http-equiv=3D'refresh' content=3D'0;url=3Dthankyou.php?fname=[/color
]
=3D
> $fname'> ");
> redirectingthepage();
> exit;
>
> i have used the above code so that even if the echo (" <meta http-
> equiv=3D'refresh' content=3D'0;url=3Dthankyou.php?fname=3D$fname'>
>
> "); is not executed the redirectingthepage() function will be
> executed.
>
> my question is due to the structure of the page whatever text is
> present before the form that text is appearing again
>
> followed by the text i have inside redirectingthepage() function, i do
> not want this to happen. i would like what is written
>
> in redirectingthepage() function only to appear. i have defined
> redirectingthepage() function in a separate file and i am
>
> calling the file which has redirectingthepage() function by using
> include statement in the registration page.
>
> please advice how i can display what is defined in
> redirectingthepage() function ONLY if the refresh is disabled by the
> user
>
> thanks.
Hi.
Headers, as their name suggests, must be sent before any other
output. There is no way around this, it's just a fact of how HTTP
works. First it sends the headers, then a blank line, then the
document content (the HTML). Any PHP code (or indeed HTML code
embedded in your PHP) that is sent to the browser triggers the sending
of the blank line, so it's too late to send any more headers after
this point.
The proper solution to this problem would be to refactor your code to
remove any output that occurs prior to the header being sent. The
pattern I typically use for what you're doing (a form that submits to
itself and redirects somewhere else on success) is as follows:
<?php
if ($_POST)
{
if (Your test for valid form data here)
{
if (Database update here)
{
header ('Location: http://your.location.here');
die ();
}
else
{
$errors =3D 'Could not submit to database';
}
}
else
{
$errors =3D 'Form data inorrect';
}
}
>?
<html>
<head>
</head>
<body>
</body>
<php
// Output any error messages here
if ($errors)
{
echo ('<div class=3D"error">' . $errors . '</div>');
}
?>
<form action=3D"<?php echo ($_SERVER ['PHP_SELF']); ?>" method=3D"post">
<!-- your form goes here -->
</form>
</html>
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.