无法将序列化的数组从html传递到较低的php文件。

时间:2021-07-14 07:44:18

I am trying to pass an array of checkbox inputs from an html, to initial php which generates a new page layout and then called another php to populate it. The php files are using the serialize and unserialize commands on the array variable argument but it not working correctly.

我尝试从一个html中传递一个复选框的数组,到初始php,它生成一个新的页面布局,然后调用另一个php来填充它。php文件在数组变量参数上使用序列化和非序列化命令,但它不能正常工作。

The initial html form is basically doing this:

最初的html表单是这样做的:

  <form name="ppFrom" action="pp_GeneratePage.php" method="post">

  <h2>Filter out the following TDRSSes or Ground Stations:</h2>
  <input id="cfButton" type="button" value="Clear filters" onclick="toggleOff(this);" /><br>
  <input type="checkbox" name="Filter[]" value="SGS">SGS 
  <input type="checkbox" name="Filter[]" value="AGS">AGS 
  <input type="checkbox" name="Filter[]" value="SKS">SKS 
  <input type="checkbox" name="Filter[]" value="WPS">WPS 
  <input type="checkbox" name="Filter[]" value="PF1">PF1<br>
  <input type="checkbox" name="Filter[]" value="171">171 
  <input type="checkbox" name="Filter[]" value="TDW">TDW 
  <input type="checkbox" name="Filter[]" value="TDE">TDE 
  <input type="checkbox" name="Filter[]" value="TR3">TR3 
  <input type="checkbox" name="Filter[]" value="275">275<br>

In the pp_GeneratePage.php I can print out the check items ok (I checked SGS and AGS): print_r($_POST['Filter']); prints output: Array ( [0] => SGS [1] => AGS )

pp_GeneratePage。我可以打印检查项(我检查了SGS和AGS): print_r($_POST['Filter']);打印输出:数组([0]=> SGS [1] => AGS)

The problem starts when I try and pass the Filter array down to the php file which does the real work. This is the code I see when I do view source command:

当我尝试将筛选器数组传递到执行实际工作的php文件时,问题就开始了。这是我在查看source命令时看到的代码:

<frame name="AquaMB" src="pp_ContactRangesPanel.php?sc=Aqua&path=/var/www/html/java_clocks/Aqua/terra_aos_times&filter=a:2:{i:0;s:3:"SGS";i:1;s:3:"AGS";}#target" scrolling=auto frameborder=0>

As you can see I have 3 arguments being passed to the pp_ContactRangesPanel.php file via the src parameter: sc=Aqua, path=/var/www/html/java_clocks/Aqua/terra_aos_times, and an array Filter which I serialized to filter=a:2:{i:0;s:3:"SGS";i:1;s:3:"AGS";}.

正如您所看到的,我有3个参数被传递给pp_ContactRangesPanel。php文件通过src参数:sc=Aqua, path=/var/www/html/java_clocks/Aqua/terra_aos_times,以及一个数组过滤器,我将其序列化为Filter =a:2:{I:0;s:3:“SGS”;

This is the print code:

这是打印代码:

$filterList = serialize($_POST["Filter"]);
printf ("<frame name=\"%sMB\" src=\"pp_ContactRangesPanel.php?sc=%s&path=%s&filter=%s#target\" scrolling=auto frameborder=0>\n", $aMissions[$c], $aMissions[$c], $MissionInputPaths[$aMissions[$c]], $filterList);

In pp_ContactRangesPanel.php I can see the first two arguments fine, but filter array is truncated as follows: I see "a:2:{i:0;s:3:" but I should see "a:2:{i:0;s:3:"SGS";i:1;s:3:"AGS";}"

在pp_ContactRangesPanel。我可以看到前两个参数很好,但是过滤数组被截断如下:我看到了“a:2:{I:0;s:3:”但是我应该看到“a:2:{I:0;s:3:“SGS”;I:1;s:3:“AGS”;}

   import_request_variables("gP", "var_");
   echo "sc $var_sc <br>";
   echo "path $var_path <br>";
   $filterList = unserialize($var_filter);
   echo "filter $filterList <br>";

output is

输出是

 sc Aqua
 path /var/www/html/java_clocks/Aqua/terra_aos_times
 filter 

If I do this instead:

如果我这样做:

$filterList = isset($_GET['filter']) ? $_GET['filter'] : null;
echo "fitler $filterList end<br>";
$afilter = unserialize($filterList);
echo "fitler2 $afilter <br>";

The out is:

是:

fitler a:2:{i:0;s:3: end
fitler2 

This is the same as if I did a

这和a是一样的。

echo "path $var_filter <br>";

So somehow the variable is being truncated so I can't unserialize it successfully. I think is the double quotes generated by the serialize command but I don't what the workaround is for it. If I pass the filter without serializing it all I see is ARRAY when I print out a entry it doesn't work.

所以这个变量被截断了所以我不能成功地将其序列化。我认为是序列化命令生成的双引号,但我不知道它的工作原理是什么。如果我在没有序列化的情况下通过过滤器,我看到的是数组,当我打印出一个条目时,它不起作用。

So what am I doing wrong? If is the double quotes, what is the workaround so it parses ok?

我做错了什么?如果是双引号,那么它的工作原理是什么?

  • Modify the serialized filter sting to do \"SGS\" or is the some
    command I can use to fix it?
  • 修改序列化的过滤器sting来做\“SGS\”或者是我可以用来修复它的一些命令?
  • Should I be using something besides printf?
  • 除了printf,我还应该使用什么吗?
  • Or am I passing these arguments in the hard way and should be doing it some other way?
  • 或者,我是否应该以另一种方式传递这些观点?

1 个解决方案

#1


0  

As a workaround I replaced the double quote with underscores to successfully pass the serialized array information down. See example:

作为一个解决方案,我用下划线替换了双引号,以成功地传递序列化的数组信息。看到的例子:

$filterListRaw = serialize($_POST["Filter"]); $filterList = str_ireplace('"', '_', $filterListRaw);

$ filterListRaw =序列化($ _POST["过滤器"]);$filterList = str_ireplace(' ', '_', $filterListRaw);

In the called html file I then restore the double quotes and then unserialize. $filterListRaw = str_ireplace('_', '"', $var_filter); $filterList = unserialize($filterListRaw);

在所谓的html文件中,我将恢复双引号,然后取消序列化。$filterListRaw = str_ireplace('_', ' ', $var_filter);filterListRaw美元$ filterList = unserialize();

I still think I am doing this the hard way.

我仍然认为我是在艰难地做这件事。

#1


0  

As a workaround I replaced the double quote with underscores to successfully pass the serialized array information down. See example:

作为一个解决方案,我用下划线替换了双引号,以成功地传递序列化的数组信息。看到的例子:

$filterListRaw = serialize($_POST["Filter"]); $filterList = str_ireplace('"', '_', $filterListRaw);

$ filterListRaw =序列化($ _POST["过滤器"]);$filterList = str_ireplace(' ', '_', $filterListRaw);

In the called html file I then restore the double quotes and then unserialize. $filterListRaw = str_ireplace('_', '"', $var_filter); $filterList = unserialize($filterListRaw);

在所谓的html文件中,我将恢复双引号,然后取消序列化。$filterListRaw = str_ireplace('_', ' ', $var_filter);filterListRaw美元$ filterList = unserialize();

I still think I am doing this the hard way.

我仍然认为我是在艰难地做这件事。