I'm new to web security
.After spending time reading some blogs and community sites like SO
,I have found some techniques to be safe from XSS Attack
and SQL Injection
.But the problem is,most of that security related questions are very old.So,my question is
does my following code has any major security holes that can be bypassed by amateur or mid-level attacker(hacker)
.
Is there anything else I can do to be safe from attack?By the way,I'm using HTMLPurifier
to be safe from XSS Attack
PHP
require_once '/path/to/HTMLPurifier.auto.php';
$connect_dude=mysqli_connect('localhost','root','','user');
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
if(isset($_POST["sub"])){
$name=$_POST["namex"];
$email=$_POST["email"];
$ques=$_POST["ques"];
$clean_name = $purifier->purify($name);
$clean_email = $purifier->purify($email);
$clean_ques = $purifier->purify($ques);
$stmt = mysqli_stmt_init($connect_dude);
if(mysqli_stmt_prepare($stmt, 'INSERT INTO question (name,email,question) VALUES(?,?,?)')) {
mysqli_stmt_bind_param($stmt, "sss", $clean_name, $clean_email, $clean_ques);
mysqli_stmt_execute($stmt);
}
}
HTML FORM
<div id="form">
<form id="sub_form" action="ask.php" method="post" enctype="multipart/form-data">
<p id="nam" class="indi">Name</p><input type="text" id="namex" name="namex" placeholder="Your Name" required></br>
<p id="ema" class="indi">Email</p><input type="text" id="email" name="email" placeholder="Email" required></br>
<p id="que" class="indi">Question</p><textarea id="ques" name="ques" placeholder="Question" required></textarea></br>
<input type="submit" id="sub" name="sub" value="Send">
</form>
</div>