0

I have some variables from database. So Can anybody tell me What would be the best method to sanitize these data before before using them (echoing)?

This is my variables -

$username
$email
$mobile
$domain
$sub_domain
$cpanel_username
$cpanel_password
$period
$domain_registered

So I tried to sanitize them using these method.

$db_username        = preg_replace("/[^a-zA-Z0-9_\-]+/", "", $username);
$db_email           = filter_var($email, FILTER_SANITIZE_EMAIL);
$db_mobile          = filter_var($mobile,FILTER_SANITIZE_NUMBER_INT);
$db_domain      = filter_var($domain, FILTER_SANITIZE_URL);
$db_subDomain      = filter_var($sub_domain, FILTER_SANITIZE_URL);
$db_cpanelUsername  = preg_replace("/[^a-zA-Z0-9_\-]+/", "", $cpanel_username);
$db_cpanelUassword  = $cpanel_password;
$db_period      = (int)$period; 
$db_domainRegistered = preg_replace("([^0-9-])", "", $domain_registered);

Can somebody tell me this way is correct or not? Thank you.

user3733831
  • 2,059
  • 7
  • 26
  • 53
  • possible duplicate of [What are the best PHP input sanitizing functions?](http://stackoverflow.com/questions/3126072/what-are-the-best-php-input-sanitizing-functions) – baao Jan 18 '15 at 08:35
  • @michael, I checked that question before ask this one. But Still I am confusing about something. – user3733831 Jan 18 '15 at 08:38

0 Answers0