PHP equivalent to meta http refresh

Hi everyone,

I’m working on a very basic contact form for my portfolio as opposed to using the generic script dreamhost provides. I have two questions hopefully someone can bring some insight into.

  1. When an error occurs in the form, the user is sent to the formhandler.php which provides them with the errors, however, since my page is a one page portfolio they are redirected to the top of the page, but my form is at the bottom. I used the code, and it produces the results I want to a certain extent. The problem is, if you try to reload the page, it is sent into a loop of death in which the page continously refreshes itself. I am hoping there is a solution to this via php. I have seen some examples around but I cannot quite grasp the concept. Would anyone be able to provide me with some resources or solutions to this issue?

  2. My second issue is with the form itself. If the user errors the form out, sometimes what will happen is the text blinker or the content itself will not be display directly in the form, but actually way below it. The only way it corrects itself is when the user goes clicks back onto the textfield of the form. This ONLY happens in Firefox so far, IE does not seem to have this bug. Does anyone know or heard of this issue before? I can provide a screenshot if needed, but you can test it yourself by going to my beta test page: .



php indeed has something that will achieve the same thing…

header(‘Location: /index.html’);

the path after Location: can be any page in your site. If you need to you can also include #anchorname in there too to move the page to any specified anchor…

not familiar with your 2nd problem - are you using some javascript??? if you are then I suggest try doing so without (you should NOT be validating data entry with javascript alone - it should be checked by php; add js validation just to make users lives easier)

The screenshot might be helpful … I just tested the form in FF (ubuntu linux) and could not recreate the error.


Screenshot is here:

Notice the cursor blinker is way below the form, I cannot figure out what is causing this error. There is absolutely no javascript on my page. I did try the header function however it was giving me errors previously. I will try that again once more.


I now see what you mean (from looking at the screenshot), but I’m sorry to report I don’t have any idea why it is doing that (as I said, I can’t duplicate it with my browser). :wink:


Interesting… could it be an issue with Vista 64bit in firefox, maybe some issue with rendering? As I said once you click the text area it all goes back to the way it should. I will try it on several different OS’s to see what the deal is.

Also, back to the header question: My php code is the following and I am getting a header error. I am fairly new to php therefore my troubleshooting skills are pretty limited.

<? $name = $_POST['realname'] ; $email = $_POST['email'] ; $message = $_POST['message'] ; $errorFlag = false; $errorEmail = false; $errorName = false; $errorMessage = false; if (!$name) {$errorFlag = true; $errorName = true;} if (!$email) {$errorFlag = true; $errorEmail = true;} if (!$message) {$errorFlag = true; $errorMessage = true;} if ($errorFlag == true) { ?> <?php header('Location: formhandler.php#contactnav'); ?>

An error has occured:

    <?php if ($errorName = true) {echo "
  • The following fields are required: Name
  • ";} ?> <?php if ($errorEmail = true) {echo "
  • The following fields are required: Email
  • ";} ?> <?php if ($errorMessage = true) {echo "
  • The following fields are required: Message
  • ";} ?>
<?php } else { ?> <?php mail( "", "Pedrazzini Design Form Submission", $message, "From: $name $email" ); header('Location: formhandler.php#contactnav'); ?>

Submission successful!

Thank you for your form submission. Sit back and relax, your inquiry will be looked into shortly.

<?php } ?>

I get the following error:

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Portfolio Site\formhandler.php:14) in C:\xampp\htdocs\Portfolio Site\formhandler.php on line 496

All of this php is happening inside the formhandler.php itself, do headers error out if they are directed towards stuff inside their own file?

Thanks for the help so far,


you can’t send headers once you have started outputting html (or just white space) basically the first time you echo, print or break out of php.

the solution is to either do all the necessary checks BEFORE you output any message or place ob_start() at the beggining of yoru script and ob_end_flush() at the end.

I’m looking up that function at However it seems a bit complicated for my current knowledge. Would anyone be able to give me an example of how to implement it in the code I provided above?