Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other checking the contents of a variable on PHP

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #24056
    ikthius
    Member

    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

    #53545

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

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

    http://us.php.net/preg-match

    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.

    #53572
    Argeaux
    Participant

    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.

    #53577

    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)
  • The forum ‘Other’ is closed to new topics and replies.