Give help. Get help.

  • # January 27, 2009 at 12:43 pm

    Hey everyone,

    A question about PHP.

    I want to have a PHP script that has the ability to check a variable for certain values.

    lets say I want to check to see if a text string contains [url-http// somewhere in the variable, how can I test for this?
    I am thinking an if statement, but how can I check for the occurrence of certain parts of a variable

    # January 27, 2009 at 1:00 pm

    you could use preg_match() to search for a regular expression. For example:

    if (preg_match(“{[url-http//}”, $content))

    The opening and closing brackets around the string that you are searching for are necessary, because the define the beginning and end of the regular expression.

    # January 28, 2009 at 5:18 am

    Well thats not gonna fix the spamproblem problem.
    Its better to use some sort of captcha or an other option. If you google for contact form spam there are lots of little things you can do.

    # January 28, 2009 at 1:13 pm

    Yes, $content is the variable you are checking.

    I’m not sure why it isn’t working for you, but it is a method I am using with success on my site. Basically, I use preg_match() to check the contents of the message that the user is trying to send to me. If they match a regular expression I have set up (I am checking for values such as "href" and "link="), I generate an error and ask the user to correct the input.

    No, it won’t ultimately fix the spam problem, but it will catch the sort of spam you are getting, and should block it from coming through, at least as long as it has the "href" and other values I am checking for.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.