标题php不工作
嗯,我试图使用标题发送信息,但是我的html已经在输出信息,我试图通过使用ob_start()函数来解决这个问题,但没有效果标题php不工作,php,header,Php,Header,嗯,我试图使用标题发送信息,但是我的html已经在输出信息,我试图通过使用ob_start()函数来解决这个问题,但没有效果 ob_start(); require('RegisterPage.php'); if(isset($_POST['register'])) { if(register($errormsg,$regnumber)) { $to = $_POST['email']; $subject =
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');
}
else $error=$errormsg;
}
ob_end_flush();
在这里,您试图重定向到其他页面并显示一条消息。这不可能发生 相反,请尝试使用链接或回显:
<meta http-equiv="Refresh" content="(delay in seconds);URL=(destination)">
在您的
中
在您的情况下,您希望这是即时的,因此:
<meta http-equiv="Refresh" content="0;URL=emailNotification.html">
更好的选择是,不需要页面,直到
之后,如果您需要在任何输出发生之前调用ob\u start
。因此,例如,作为主PHP脚本文件中的第一条语句(如果我没有记错,请确保在执行PHP脚本结束时执行头();之前没有任何内容),因此请尝试将其移动到If的开头
干杯您必须缓冲html输出,而不是php逻辑。例如:
ob_start();
<html>...
/* PHP */
...
ob_end_flush();
ob_start();
...
/*PHP*/
...
ob_end_flush();
检查ob_start()函数之前包含的脚本是否输出HTML。有时包含的文件可能在PHP结束标记后包含空格。该空格将按原样输出。若要解决此问题,请保留文件中的PHP结束标记
例如
这会让你头疼。这很好,可以解决上述问题:
<?php
class someClass {
...
}
位置后1个空格:
和
完整url
使用动态HTTP_主机
header('Location: http://'.$_SERVER["HTTP_HOST"].'/emailNotification.html');
克里斯
header('Location: http://www.foo.com/emailNotification.html');
header('Location: http://'.$_SERVER["HTTP_HOST"].'/emailNotification.html');