如何将check_plain函数循环到这个数组中?

时间:2016-06-06 16:06:08

标签: php

我想将这个check_plain函数与以下内容结合起来,但我并不熟悉PHP。这些值是从"谢谢你"的网址中检索出来的。购买后客户登陆的页面,然后在页面的其他位置回显,但是我注意到这是一个潜在的安全问题,因此建议使用checkplain。

<?
  function check_plain($text) {
  return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
  }
?>


<?php 
  $email=$_GET["email"];
  $itemdesc=$_GET["itemdesc"];
  $totalpaid=$_GET["totalpaid"];
  $bookingnum=$_GET["bookingnum"];
?>

3 个答案:

答案 0 :(得分:2)

您可以将check_plain函数应用于$_GET数组中的每个元素,如下所示:

$escapedGet = array_map('check_plain', $_GET);

然后像这样使用它:

$email = $escapedGet["email"];

答案 1 :(得分:0)

所以如果我理解正确,你想在值上调用check_plain函数......

$email = check_plain($_GET["email"]);
$itemdesc = check_plain($_GET["itemdesc"]);
$totalpaid = check_plain($_GET["totalpaid"]);
$bookingnum = check_plain($_GET["bookingnum"]);

答案 2 :(得分:0)

您可以使用这个简单的function

<?php

 function check_plain($text) {
  return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
  }
 $user_details = array_map('check_plain', $_GET);

$email=$user_details["email"];
$itemdesc=$user_details["itemdesc"];
$totalpaid=$user_details["totalpaid"];
$bookingnum=$user_details["bookingnum"];

&GT;

了解有关array_map的更多信息。请参阅http://php.net/manual/en/function.array-map.php