Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Member
    Join Date
    Jul 2002
    Posts
    367

    Default contact us script and spame help

    We received the complain about spamming using contact us php script. How can we prevent it ? we disabled it and client go mad. Can we optimize or can we prevent?

    thanks
    shann

  2. #2
    Member Gareth's Avatar
    Join Date
    Feb 2004
    Location
    Isle of Anglesey, UK
    Posts
    73

    Default

    The only way to prevent it is to secure the script (ie: rewrite it so that spammers can not connect to it and send spam though it).

    Or change it for a more secure script.
    HostOrca - hostorca.co.uk
    UK and US Reliable Shared Hosting Solutions
    Where Customer Service Counts!

  3. #3
    ckh
    ckh is offline
    Member
    Join Date
    Dec 2003
    Posts
    333

    Default

    Spammers inject headers into some of the fields which allows it to send out spam.

    I've been able to stop it by putting all of the fields filled out by a visitor in the body. For example:

    $name
    $email
    $subject
    $comment

    Might be filled out by a visitor and passed on to be processed. I'll then do something like:

    $to = "myEmail@address.com";
    $subject2= "Contact Request";

    $body = "

    Contact Information

    Name: $name
    E-mail: $email
    Subject: $subject

    Comments:

    $comment";

    mail("$to", $subject2, $body, "FROM: $to");

    This way anything they try to inject into the headers can't be done as it's in the body of the email.

    Chris

  4. #4
    Member
    Join Date
    Jun 2004
    Location
    Southern California
    Posts
    255

    Default use sessions

    you can also use a session to create sometype of unique hash value with some key types.

    Then add that value to a session variable.
    pass the session id thru the form.

    Grab the session id and retrieve the variable
    Then reverse the hash process to ensure its a valid hash that is associated to the session id, then once the email is sent successfully, unset and destroy the session.

    This also keeps users from clicking the refresh key to send more spam.
    your golden.
    This also makes users visit the form page to send email, and not just post directly to your mail function.... get it?

  5. #5
    Member brianoz's Avatar
    Join Date
    Mar 2004
    Location
    Melbourne, Australia
    Posts
    1,117
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    I just put
    PHP Code:
    include 'antispam.php'
    at the top of any questionable script. The antispam.php script is a script that checks for bogus POST variable attempts and dies if it finds any. That way you don't have to go through and fix all the broken contact scripts on your server.

  6. #6
    Member brianoz's Avatar
    Join Date
    Mar 2004
    Location
    Melbourne, Australia
    Posts
    1,117
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by t9clkclnr
    you can also use a session to create sometype of unique hash value with some key types.
    This is actually a really nice solution.

    You don't need to make the hash unique though, it's enough to use a session on the server. To get something like this to work, change the extension of the form html file from .htm to .php, and add the following line in it somewhere:

    PHP Code:
    <?php start_session(); $_SESSION['unsent'] = 1?>
    then in your submit script add the following lines:

    PHP Code:
    if (empty($_SESSION['unsent']) { die "no session or already sent"; }
    $_SESSION['unsent'] = 0
    I'm not sure if I got this right and it's entirely untested, but it's close.

  7. #7
    Member
    Join Date
    Jan 2005
    Posts
    1,880

    Default

    For the accuracy of checking whether the session variable is set, it is better to use boolean values and the 'identical' operator.

    e.g.
    PHP Code:
    <?php

    session_start
    ();
    $_SESSION['unsent'] = true;

    // .....

    if ($_SESSION['unsent'] === true) {
        
    // ....
    }

    ?>

  8. #8
    Member brianoz's Avatar
    Join Date
    Mar 2004
    Location
    Melbourne, Australia
    Posts
    1,117
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by webignition
    For the accuracy of checking whether the session variable is set, it is better to use boolean values and the 'identical' operator.
    I think it's true that I should have used "true" instead of "1", just to make the code a little more self-documenting. I can't see any value at all in using the identical operator here, but perhaps I'm missing something. Perhaps if the code was more complex there might be some value, but not here.

    The empty() function I used is a PHP builtin that returns true if a variable is unset or has null or "" or 0 (ie zero) in it.
    Last edited by brianoz; 08-16-2006 at 09:44 AM.

Similar Threads & Tags
Similar threads

  1. Contact Form PHP script problem
    By sjosue96 in forum New User Questions
    Replies: 2
    Last Post: 05-09-2011, 07:32 PM
  2. Replies: 2
    Last Post: 08-25-2009, 05:33 PM
  3. Is it possible to stop one contact script sending as nobody.
    By MarcelB in forum E-mail Discussions
    Replies: 3
    Last Post: 09-10-2007, 09:29 AM
  4. problem with spame protect!
    By cvirak in forum E-mail Discussions
    Replies: 1
    Last Post: 07-05-2007, 09:26 AM
  5. /script to update contact info
    By h2oski in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 02-20-2004, 07:38 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube