开发者

header php not working

well am trying to use the header to send information, but my html is already outputting information, I tried to fix the problem by using the ob_start() function to no avail

    ob_start();
    require('RegisterPage.php');
    if(isset($_POST['register']))
    {
      if(register($errormsg,$regnumber))
      {
        $to = $_POST['email'];
        $subject = "Registration";
        $txt = "You need to return to the Classic Records homepage and enter the number given in order to finish your registration ".$regnumber."";
        $headers = "From: registration@greenwichtutoring.com";
        mail($to,$subject,$txt,$headers);
        header('Location:emailNotification.html');
      }
开发者_JS百科      else $error=$errormsg;
    }
    ob_end_flush();


Check if any scripts included before the ob_start() function are outputting HTML. Sometimes an included file can contain a space after the PHP closing tag. That space will be outputed as is. To fix this, leave the PHP closing tag from your file.

E.g.

<?php
 class someClass {
  ...
 }
?><whitespace>

Can give you some good headaches. This is fine and fixes the above problem:

<?php
 class someClass {
  ...
 }


You need to call ob_start before any output has happened. So, for example, as the first statement in your main PHP script file (make sure that there is nothing before your <?php like some whitespace of a BOM).


Here you're trying to redirect to a different page and show a message. It can't happpen.

Instead, try using a link, or echo-ing:

<meta http-equiv="Refresh" content="(delay in seconds);URL=(destination)">

in your <HEAD>.

In your case, you want this to be instant, so:

<meta http-equiv="Refresh" content="0;URL=emailNotification.html">

The better alternative, is simply to not require the page until after the if.


If i remember correctly the header(); is executed at the end of the execution of the php script , so try moving it in the beginning of the if

Cheers


You have to buffer the html output, not the php logic. E.g:

ob_start();
<html>...
/* PHP */
...
ob_end_flush();


header('Location: http://www.foo.com/emailNotification.html');

1 space after Location:

and

full url

With Your Dynamic HTTP_HOST

header('Location: http://'.$_SERVER["HTTP_HOST"].'/emailNotification.html');

Chris.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜