I am using a javascript date picker that allows the user to select a date. However, I would like to also sanitize the posted date data before entering into the database. I am not seeing any sanitize filter here: http://us2.php.net/manual/en/filter.filters.sanitize.php
What would be the best method to sanitize a date before entering into a database?
This would be the original value from the post:
$datepick = $_POST['date'];
// wich is 04/12/2014
Then I convert it for the database:
$date = date("Y-m-d", strtotime($datepick));
Thanks!
There are four primary methods to achieve data sanitization: physical destruction, data erasure, cryptographic erasure, and data masking.
Data sanitization is the process of irreversibly removing or destroying data stored on a memory device (hard drives, flash memory / SSDs, mobile devices, CDs, and DVDs, etc.) or in hard copy form.
If your date is like "03/02/2014" then you can simply clean your variable by regexp: $date = preg_replace("([^0-9/])", "", $_POST['date']);
The primary use of data sanitization is for the complete clearing of devices and destruction of all sensitive data once the storage device is no longer in use or is transferred to another Information system .
If your date is like "03/02/2014" then you can simply clean your variable by regexp:
$date = preg_replace("([^0-9/])", "", $_POST['date']);
This allows only digits (0-9) and fwd slash (/).
Formatting the date sanitizes it, because:
This is true of:
DateTime::format
DateTimeImmutable::format
DateTimeInterface::format
date_format()
Date($format, $date_string)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With