Php 如何修复标题新行错误
我收到以下错误消息“标头可能不包含多个标头,检测到新行”。我知道它表示检测到新行,但我无法确定这行来自何处。我试着修剪变量。我用不同的方式重新写了标题行,没有任何结果。我添加了getallheaders函数以查看传递的内容,但在输出$headers中没有看到新行或任何额外字符。即使使用ob_start()也无济于事Php 如何修复标题新行错误,php,header,Php,Header,我收到以下错误消息“标头可能不包含多个标头,检测到新行”。我知道它表示检测到新行,但我无法确定这行来自何处。我试着修剪变量。我用不同的方式重新写了标题行,没有任何结果。我添加了getallheaders函数以查看传递的内容,但在输出$headers中没有看到新行或任何额外字符。即使使用ob_start()也无济于事 <?php ob_start(); include "catalog.obj"; session_start(); $catalogObj = $_SESSION['cat
<?php
ob_start();
include "catalog.obj";
session_start();
$catalogObj = $_SESSION['catalogObj'];
if (isset($_POST['st']))
$st = $_POST['st'];
else
$st = '0';
if (isset($_POST['num']))
$num = $_POST['num'];
else
$num = '0';
if (isset($_POST['type']))
$type = $_POST['type'];
else
$type = '0';
if (isset($_POST['rec']))
$rec = $_POST['rec'];
else
$rec = '0';
if (isset($_POST['option']))
$option = $_POST['option'];
else
$option = '0';
if(strcmp($_POST['submit'],"Reset Form") == 0)
{
header("location: search_catalog.php?type=$type&firstTime=1");
exit;
}
elseif(strcmp($_POST['submit'],"Catalog Administration") == 0)
{
Header("Location: administration.php");
exit;
}
else
{
$inventory_id_num = $_POST['inventory_id_num'];
$inventory_desc = $_POST['inventory_desc'];
$inventory_revision = $_POST['inventory_revision'];
$quantity = $_POST['quantity'];
$catalog_status_id = $_POST['catalog_status_id'];
$order_form_type_id = $_POST['order_form_type_id'];
$catalogObj->inventory_id_num = $inventory_id_num;
$catalogObj->inventory_desc = $inventory_desc;
$catalogObj->inventory_revision = $inventory_revision;
$catalogObj->quantity = $quantity;
$catalogObj->catalog_status_id = $catalog_status_id;
//$catalogObj->order_form_type_id = array();
$catalogObj->order_form_type_id = $order_form_type_id;
$count=count($order_form_type_id);
for ($i=0; $i<$count; $i++)
{
//print "order_form_type_id: $order_form_type_id[$i]<br>";
if(strlen($order_form_type_id[$i]) > 0)
{
$catalogObj->order_form_type_id[$i] = $order_form_type_id[$i];
}
}
if(strcmp($_POST['submit'],"Back to Order Form") == 0)
{
Header("Location: order_form.php?num=$num");
exit;
}
else
{
//$url = "type=".$type."option=".$option."rec=".$rec."st=".$st."num=".$num;
Header("location: search_catalog_handler.php?type=$type&option=$option&rec=$rec&st=$st&num=$num");
//Header("location: search_catalog_handler.php?" . rawurlencode($url));
if (function_exists('getallheaders'))
{
$headers = getallheaders();
print_r( $headers);
}
exit;
}
}
function getallheaders()
{
$headers = '';
foreach ($_SERVER as $name => $value)
{
if (substr($name, 0, 5) == 'HTTP_')
{
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
?>
假设
catalog.obj
没有向浏览器输出任何信息(这也会导致错误),则$type
变量看起来像是罪魁祸首,因为它是唯一的通配符
请注意,您需要对脚本中要在URI中使用的所有POST
ed变量执行以下操作:
既然$type
可能是任何东西(它有时使用POST
ed变量),您应该在将其吐回页眉之前将其清理干净:
$type = urlencode($type); // Prepares the variable to be inserted in the URI
header("Location: search_catalog.php?type=$type&firstTime=1");
首先,谢谢你的指点!上面代码中的问题是$st变量。我对标题和重写标题不是很有经验,但我添加了以下条件声明:
if (!empty($_POST['st']))
{
$st = $_POST['st'];
$num = $_POST['num'];
$type = $_POST['type'];
$rec = $_POST['rec'];
$option = $_POST['option'];
}
到我的代码的开头,因此完整的代码是:
<?php
ob_start();
/*************************************
altered complete 12/20/2013
rjm
*************************************/
include "catalog.obj";
session_start();
$catalogObj = $_SESSION['catalogObj'];
if (!empty($_POST['st']))
{
$st = $_POST['st'];
$num = $_POST['num'];
$type = $_POST['type'];
$rec = $_POST['rec'];
$option = $_POST['option'];
}
if(strcmp($_POST['submit'],"Reset Form") == 0)
{
header("location: search_catalog.php?type=$type&firstTime=1");
exit;
}
elseif(strcmp($_POST['submit'],"Catalog Administration") == 0)
{
Header("Location: administration.php");
exit;
}
else
{
echo "<pre>";
print_r($_POST);
echo "</pre>";
//exit;
$inventory_id_num = $_POST['inventory_id_num'];
$inventory_desc = $_POST['inventory_desc'];
$inventory_revision = $_POST['inventory_revision'];
$quantity = $_POST['quantity'];
$catalog_status_id = $_POST['catalog_status_id'];
$order_form_type_id = $_POST['order_form_type_id'];
$catalogObj->inventory_id_num = $inventory_id_num;
$catalogObj->inventory_desc = $inventory_desc;
$catalogObj->inventory_revision = $inventory_revision;
$catalogObj->quantity = $quantity;
$catalogObj->catalog_status_id = $catalog_status_id;
$catalogObj->order_form_type_id = $order_form_type_id;
$count=count($order_form_type_id);
for ($i=0; $i<$count; $i++)
{
if(strlen($order_form_type_id[$i]) > 0)
{
$catalogObj->order_form_type_id[$i] = $order_form_type_id[$i];
}
}
if(strcmp($_POST['submit'],"Back to Order Form") == 0)
{
Header("Location: order_form.php?num=$num");
exit;
}
else
{
Header("location: search_catalog_handler.php?type=$type&option=$option&rec=$rec&st=$st&num=$num");
exit;
}
}
?>
这允许从发送页面进行特定类型搜索(带参数)和常规类型搜索(无参数)。什么是catalog.obj??根据此处突出显示的语法,这一行可能有错误
标题(“位置:search_catalog_handler.php?type=$type&option=$option&rec=$rec&st=$st&num=$num”)代码>并且您正在使用POST
。URL本身应该是,理论上取自GET
这是导致问题的一行!我正在更新一个11年前编写的php站点。原始编写器使用POST传递headers函数中使用的数据的一半时间。就像这里的情况一样。我有三周的时间来更新108个与此类似的php代码文件…如何在不重写所有内容的情况下修复此问题?然后尝试使用rawurlencode
,如$type=rawurlencode($type);标题(“位置:search_catalog_handler.php?type=$type&option=$option&rec=$rec&st=$st&num=$num”)代码>从上的答案中找到,因此我在另一个网站上找到。请参见条目#4
,但您需要将ereg\u replace
替换为preg\u replace
或preg\u match
等效项。抱歉,这一行代码不是问题所在。这是“Header”(“location:search_catalog_handler.php?type=$type&option=$option&rec=$rec&st=$st&num=$num”);". 有什么建议吗?urlencode没有帮助。如果var_dump()
整个字符串,从搜索目录开始…
?抱歉,我现在打印标题时遇到问题。它现在正在进行,但没有传递参数…如果您不介意的话,我将在一段时间内与您联系,或者明天的第一件事。漫长的一天…这让我在一天中的大部分时间都在转圈。下面是我现在得到的是“数组([Connection]=>keep alive[Content Length]=>571[Content Type]=>application/x-www-form-urlencoded[Accept]=>text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8[Accept-Encoding]=>gzip,deflate[Accept-Language]=>en-US,en;q=0.5[Cookie]=>PHPSESSID=ru8p2punaaaqp9vkio622jh5[主机]=>www.gmacestest.com[Referer]=>[User Agent]=>Mozilla/5.0(Windows NT 6.1;WOW64;rv:25.0)Gecko/20100101 Firefox/25.0)“啊,这毕竟是一个圆满的结局。很高兴知道你找到了解决方案。