Jake Jake - 5 months ago 14
PHP Question

How to loop check_plain function into this array?

I'd like to combine this check_plain function with the following , but I'm not that familiar with PHP. These values are retrieved from the URL of a "Thank You" page a customer lands on after purchase, then echo'ed elsewhere on the page, but it's been brought to my attention this is a potential security issue, and hence checkplain was recommended.

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


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

Answer

You can use this simple 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"];

?>

for more info about array_map.Please refer http://php.net/manual/en/function.array-map.php

Comments