Forum Moderators: coopster

Message Too Old, No Replies

Strpos trouble

         

Pico_Train

9:35 am on Aug 11, 2008 (gmt 0)

10+ Year Member



Hi there,

I'm trying to check for a couple strings in various input elements in one of my forms and if they exist send the user somewhere else to get rid of spamming. This is the code I have that does not work at present.

$reject = "string1";

$bad_url = "string2";

$bad_link = "string3";

$pos = strpos($_POST['email'], $reject);

$comments = $_POST['comments'];

$mess_url = strpos($comments, $bad_url);

$mess_link = strpos($comments, $bad_link);

if($pos === true ¦¦ $mess_url === true ¦¦ $mess_link === true )
{
header("Location:http://www.example.com", true);
exit();

}

Any help would be much appreciated.

Thanks!

Sekka

11:14 am on Aug 11, 2008 (gmt 0)

10+ Year Member



The PHP documentation could help you here. Please see strpos() [uk2.php.net].

Just to save you some reading, strpos() returns an interger (which represents the index of where the needle string is within the haystack string) or false of it doesn't exist within the haystack.

Your explicit comparison of '=== true' will never work as true is never returned.

Your best bet would be to do,

if($pos !== false ¦¦ $mess_url !== false ¦¦ $mess_link !== false)

Hope this helps.

[edited by: Sekka at 11:17 am (utc) on Aug. 11, 2008]

Pico_Train

11:28 am on Aug 11, 2008 (gmt 0)

10+ Year Member



Perfect, thanks for the explanation, I understand now.