php中的头位置
“header()必须php中的头位置,php,http-headers,Php,Http Headers,“header()必须 “在发送任何实际输出之前被调用”-您可能会错过这一点。您可以在if条件中放置一个标头调用,前面加上其他代码,只要您遵循手册的建议: <?php require ('db_connect.php'); $Name = $_POST["name"]; $Email = $_POST["email"]; $Message = $_POST["message"]; if( isset($_POST["submit2"]) ) { $insertStr
“在发送任何实际输出之前被调用”-您可能会错过这一点。您可以在if条件中放置一个标头调用,前面加上其他代码,只要您遵循手册的建议:
<?php
require ('db_connect.php');
$Name = $_POST["name"]; $Email = $_POST["email"]; $Message = $_POST["message"];
if( isset($_POST["submit2"]) ) {
$insertString2 = "INSERT INTO Messages(Name,Email,Message)
VALUES('$Name','$Email','$Message')";
mysql_query($insertString2);
header("Location:register.php?msg=Successfully Send Message! You will get reply soon...");
}
?>
如果希望更改PHP.INI文件,可以打开输出缓冲,如下所示:
You can use output buffering ... by calling ob_start() and ob_end_flush() in your
script, or setting the output_buffering configuration directive on in your php.ini
or server configuration files.
打开输出缓冲后,此代码结构应该可以工作:
请尝试以下标题调用:
output_buffering = On
注意:当您使用header()时,如果您对维护与http1.0的向后兼容性有任何顾虑,那么您应该提供完整的url,包括协议,无论是“http”、“https”还是其他。此外,查询字符串还包含需要进行URL编码的字符。将要编码的值传递给urlencode()后,字符串如下所示:
// setting variables here, then:
if (condition) {
// other code here, then:
$location = "http://yourdomain.whatever/register.php";
$encoded = urlencode("Successfully Send Message! You will get reply soon...");
header("Location: $location?msg=$encoded");
exit;
}
使用PHP的部分乐趣在于它可以做一些很好的事情,比如自动解码编码的url。因此,要向用户显示消息,只需在register.php上编写类似于以下代码的代码:
Successfully+Send+Message%21+You+will+get+reply+soon...
. 它们不再得到维护。看到了吗?改为了解,并使用或-将帮助您决定哪个文件存在?验证路径等,错误?它是否会进入
register.php
?请注意,您不必在位置:
标题中指定完整的URL。最新版本说“当它具有相对引用()的形式时,通过根据有效请求URI()解析它来计算最终值”。如果浏览器支持http1.0,例如wget,然后,即使web服务器通常支持http1.1,它也可能会返回http1.0响应,在这种情况下,我的建议是保持与http1.0的向后兼容性。(见附件)
<?php echo htmlentities($_GET['msg']);
var str=location.search.substring(5);
str = decodeURIComponent( str );
str=str.replace(/\+/g, ' ');
alert(str); //Successfully Send Message! You will get reply soon...