Securing a contact form script

后端 未结 2 1847
有刺的猬
有刺的猬 2021-01-28 20:24

Hello! I am just wondering how secure is this contactform script I just made? My teacher was nagging at me a long time ago when I made my contactforms.

2条回答
  •  北海茫月
    2021-01-28 21:28

    You can use a function to validate the entries such as :

    function check_input($data)
     {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;
     }
    

    And

       

            $name      =    check_input($_POST['name']);
            $email    =    check_input($_POST['email']);
            $phone    =    check_input($_POST['phone']);
            $subject  =    check_input($_POST['subject']);
            $comments =    check_input($_POST['comments']);
    

    And

         if ($name && $email && $phone && $subject && $comments) {
             Send contact form...
    
    }
    

    and of course you can add captcha to make it more secure.

提交回复
热议问题