Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多次添加PHP标头_Php - Fatal编程技术网

多次添加PHP标头

多次添加PHP标头,php,Php,我有一个疑问: $get_ids = "SELECT unique_id FROM products GROUP BY unique_id LIMIT 10"; $id_results = mysql_query($get_ids); while($id_row = mysql_fetch_array($id_results)) { extract($id_row); $all_prods_link[] = $id_row['unique_id']; } 这将创建一个整数数组

我有一个疑问:

$get_ids = "SELECT unique_id FROM products GROUP BY unique_id LIMIT 10";
$id_results = mysql_query($get_ids);
while($id_row = mysql_fetch_array($id_results))
{
    extract($id_row);
    $all_prods_link[] = $id_row['unique_id']; 
}
这将创建一个整数数组。对于数组中的每个项,我将其附加到一个字符串中,后跟一个逗号:

foreach($all_prods_link as $all_prods)
{
    $query_string .= $all_prods.',';
}
结果如下:1,2,3,4,5,6,按预期工作

我遇到的问题是,我试图将其添加到当前URI的末尾,然后重定向到此URI,例如:

$link = $_SERVER['REQUEST_URI'] . '&product_options=' . $query_string;
$link变量看起来不错:

sales_reports.php?date_from=05%2F11%2F2017&date_to=05%2F12%2F2017&pay_status=Paid&submitfilter=Go&prodtype=all&report_type=productreports&product_options=1,2,3,4,5,6,7,8,9,10,
这正是我想要的,但是当我尝试重定向到此链接时,例如:

header("Location: $link");
我最终使用的实际URI包含$query_字符串,多次附加到该字符串,如下所示:

sales_reports.php?date_from=05%2F11%2F2017&date_to=05%2F12%2F2017&pay_status=Paid&submitfilter=Go&prodtype=all&report_type=productreports&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,&product_options=1,2,3,4,5,6,7,8,9,10,
如您所见,“&product_options”多次出现,后面是整数列表


header()函数可以这样使用吗?还是我做错了什么可怕的事

这是因为每次加载页面时都有多个重定向,php将附加产品选项而不是替换它

<?php

// Parse all request components
$request = parse_url($_SERVER['REQUEST_URI']);

// Parse incoming query sting to array
parse_str($request['query'], $queryArray);

// replace or add product_options
$queryArray['product_options'] = $query_string;

// rebuild the query
$newQueryString = http_build_query($queryArray);

$link = $request['path']. '?' . $newQueryString;

header("Location: $link");

这不是
标题
功能的故障。。。在此之前,对$link变量进行调试输出,并检查它包含的内容。“我遇到的问题是我正在尝试将其添加到当前URI的末尾”-并且当前URL是否已经包含
&product\u options=…
?如果您只是在它的末尾追加,那么您就不会对多次得到它感到惊讶。
foreach($all_prods_link作为$all_prods){$query_string.=$all_prods.','}
err,您应该使用它。@CBroe$link变量实际上包含了我需要的内容,请看我的文章中以“$link变量看起来不错”开头的部分,你能告诉我为什么标题(“Location:$link”);不完全转到$link吗?