I have stripped this code down for this question.
My users will be entering their shipping details through a form and I have attempted to sanitised the input. Everything works as expected in terms of successfully posting data. My question is more about good php practice.
$address_line1 = filter_var($_POST['address_line1'], FILTER_SANITIZE_STRING);
$address_line2 = filter_var($_POST['address_line2'], FILTER_SANITIZE_STRING);
$address_city = filter_var($_POST['address_city'], FILTER_SANITIZE_STRING);;
$address_state = filter_var($_POST['address_state'], FILTER_SANITIZE_STRING);
$address_country = filter_var($_POST['address_country'], FILTER_SANITIZE_STRING);
$address_zip = filter_var($_POST['address_zip'], FILTER_VALIDATE_INT);
I have googled and as I understand it, the filter_var()
function will strip out any HTML tags in order to leave only a string for the text based inputs and an integer for the address_zip
input.
Is this the correct method to filter out unwanted inputs and / or if there are further measures to consider for safe user inputting?
How can I test the filter_var()
function?
Should I simple post something like <h1>Hello World</h1>
?
Is that a sufficient test for input sanitization?
Your help is always appreciated.
Thanks, All
Moe