PHP security basics


SUBMITTED BY: Guest

DATE: Dec. 11, 2013, 10:24 p.m.

FORMAT: PHP

SIZE: 558 Bytes

HITS: 1140

  1. <?php
  2. // $_POST security
  3. // case 1: if the var is integer
  4. $var = (int)$_POST["param1"];
  5. // case 2: if the var is string
  6. $var = $_POST["param1"];
  7. // local-file-inclusion (LFI) & remote-file-inclusion (RFI) fix
  8. $var = str_replace(".","",$var);
  9. $var = str replace("/","",$var);
  10. // SQL injection fix
  11. $var = stripslashes($var);
  12. $var = mysql_real_escape_string($var);
  13. // now you can append it to your SQL query
  14. // secure print (xss fix)
  15. print htmlspecialchars($var);
  16. ?>

comments powered by Disqus