Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: How do I spam proof my contact form?

  1. #11
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    PHP Code:
    <?php

    // I added this:
    $_POST["message"] = 'My message is a link. <a href="http://www.something.com">Click here</a>';

    // YOUR CODE BELOW:
    if ($_POST["message"])
    {

    $message $_POST['message'];

    //check the message doesn't contain links

    if (preg_match('/<a[\s]+[^>]*?href[\s]?=[\s\""\']+(.*?)[\""\']+.*?>([^<]+|.*?)?<\/a>/'$message)) 
    {    
    echo 
    'there is a hyperlink';
    }

    else
    {
    echo 
    'No hyperlinks';
    }

    }
    exit;
    The above works as expected. I bet you have magic_quotes_gpc ON. If you can turn them off, do it, otherwise, use stripslashes() before checking for hyperlinks.

    preg_match(), when used with the first two arguments only returns either 0 or 1. With that in mind, you can test the result of the evaluation with an if statment.

    Good luck.

    J

  2. #12
    Join Date
    Apr 2006
    Posts
    205
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    Okay I take your point about it being usable in an if statement and I have some idea about what you're saying with regard to something needing to be changed.

    I've got the following working:

    PHP Code:
    <?

    $message 
    $_POST['message'];

    if (
    preg_match('/href/'$message)) {
    echo 
    'there is a hyperlink';
    }

    else {
    echo 
    'no hyperlinks';
    }

    exit;

    ?>
    Obviously I didn't want to have to simplify it that much but as you may have gathered I don't know how to write a lot of PHP. Please explain a little more if you can. I don't even know where to got to turn off my magic quotes.

    Thanks!
    Dog

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •