Prevent php web contact form spam

前端 未结 7 2127
面向向阳花
面向向阳花 2021-01-30 14:14

I am an amateur web designer, I have searched on stackoverflow.com and other websites and have found many fixes for this issue I\'m having, but none of them have worked (probabl

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 14:39

    An even simpler approach that works for me. Literally all spam that I receive(d), had a url in the message. So I filter on that, and have not received any spam messages since. I used to get about 10 a week.

    Add this under your line   $error_message = "";   in your php-file:

    if(preg_match('/http|www/i',$comments)) {
        $error_message .= "We do not allow a url in the comment.
    "; }

    The /i in the preg_match makes it case independent. The 'http' also filters for 'https'.

提交回复
热议问题