PHP头不适用于服务器,但在本地主机上工作得很好 [英] PHP header not working for server but works perfectly fine on local host

查看:139
本文介绍了PHP头不适用于服务器,但在本地主机上工作得很好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码在我的本地主机上尝试时效果很好,但是当我将它上传到我的服务器时,它无效

$'SESSION'''UID']。'','$ c> $ sendquery =INSERT INTO`message`(`from`,`to`,`subject`,`date`,`message`)VALUES 。$'toarray ['Uid']。','$ subject','$ d','$ message');
$ sendresult = mysql_query($ sendquery);
$ b $ if($ sendresult)
{
header('Location:home.php?action = inbox& success = 1');


else
{
header(Location:home.php?action = inbox& success = 2);
}

这是我的服务器还是代码问题?

解决方案

请确保在设置Location标题之前,代码中没有任何内容开始输出。

请确保您使用绝对网址(根据 HTTP样本:

  header('位置:http://'。$ _SERVER ['HTTP_HOST']。'/Home.php'); 

如果是这种情况,您的重定向应该可以正常工作。



输出已经开始的一些常见原因:


  • BOM(字节顺序标记)处理不正确

  • 警告或信息

  • 您的第一个<?php ...?>


This code below works perfectly fine when I try on my local host but when I upload it on to my server it does not work

$sendquery = "INSERT INTO `message` (`from`, `to`, `subject`, `date`,`message`) VALUES ('".$_SESSION['UID']."', '".$toarray['Uid']."', '$subject','$d', '$message')";
$sendresult = mysql_query($sendquery);

if($sendresult)
{
    header('Location: home.php?action=inbox&success=1');

}
else
{
    header("Location: home.php?action=inbox&success=2");
}

Is it a problem with my server or the code?

解决方案

Make sure nothing in your code started output before you set the "Location" header.
Make sure you use an absolute URL (as required by the
HTTP specification)

Sample:

header('Location: http://' . $_SERVER['HTTP_HOST'] . '/Home.php');

If this is the case, your redirect should work.

Some common reasons why output already started:

  • BOM (Byte order mark) not handled correctly
  • Warning or information
  • Whitespaces or any other HTML markup before your first <?php ... ?>

这篇关于PHP头不适用于服务器,但在本地主机上工作得很好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆