Results 1 to 4 of 4

Thread: ereg? Anti-Spam help!

  1. #1
    rlhanson's Avatar
    rlhanson is offline Master Glow Jedi
    Join Date
    Aug 2007
    Location
    Chapman, Kansas
    Posts
    531

    Default ereg? Anti-Spam help!

    I am using a php form processor and would like to stop web addresses from being input into the text fields.

    A couple examples of what I have in place and general syntax:

    PHP Code:
    if (strlen($_POST['comments']) > 255 )
    {
    header("Location: http://www.websitename.com/error.php");
    exit;
    }
    if (! 
    ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+'$_POST['vis_email']))
    {
    header("Location: http://www.websitename.com/error.php");
    exit;

    I've tried a couple of different things (which I haven't added above) but can't seem to get the right combination of single quotes, quotes, or brackets.
    Any help would be GREATLY appreciated!!!!!!!!!!
    Thank you,
    Lynne Hanson
    RL Hanson-Online

  2. #2
    rlhanson's Avatar
    rlhanson is offline Master Glow Jedi
    Join Date
    Aug 2007
    Location
    Chapman, Kansas
    Posts
    531

    Default

    I've got this working:
    PHP Code:
    /*ANTISPAM WEBSITES*/
    if (ereg('^www\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
    {
    header("Location: http://www.website.com/error.php");
    exit;
    }
    if (
    ereg('^[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
    {
    header("Location: http://www.website.com/error.php");
    exit;
    }
    if (
    ereg('^http\\:\\/\\/www\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
    {
    header("Location: http://www.website.com/error.php");
    exit;
    }
    if (
    ereg('^http\\:\\/\\/[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
    {
    header("Location: http://www.website.com/error.php");
    exit;

    How would I shorten this?
    Thank you,
    Lynne Hanson
    RL Hanson-Online

  3. #3
    jmarcv's Avatar
    jmarcv is offline Cranky Coder
    Join Date
    Jan 2005
    Posts
    354

    Default

    PHP Code:
    /*ANTISPAM WEBSITES*/
    if (ereg('^www\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
     
    $skipit=1;
    if (
    ereg('^[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
     
    $skipit=1;
    if (
    ereg('^http\\:\\/\\/www\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
     
    $skipit=1;
    if (
    ereg('^http\\:\\/\\/[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
     
    $skipit=1;
    if (
    $skipit) {
     
    header("Location: http://www.website.com/error.php");
     exit;

    The above shortens by using a flag if there is a match and redirecting in one place. This way if you change the error page it only happens in one place.

    Note also I am using the short version of IF, where if you only execute ONE command, you dont need the brackets.

    Shortening the REGEX -
    PHP Code:
    if (ereg('^[http\\:\\/\\/]*[www\\.]*[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments'])) 
    I think this should work. Note the brackets. By putting a * after instead of + you indicate that it is an optional match.
    Note, the ^ means search from the beginning of the comments field, so if the URL is not the first thing in comments, it will pass, so I am not sure you want it in there.

  4. #4
    rlhanson's Avatar
    rlhanson is offline Master Glow Jedi
    Join Date
    Aug 2007
    Location
    Chapman, Kansas
    Posts
    531

    Default

    John-Marc!!!!!!!!!!!! Welcome back!

    Thanks for the help - I'm trying this now.

    Update: Your a gem - it works GREAT! Thank you so much!
    Last edited by rlhanson; 10-19-2007 at 09:32 AM. Reason: updating info
    Thank you,
    Lynne Hanson
    RL Hanson-Online

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16