Jump to content

Recommended Posts

Ok so I've recently added strpos checking. I got username to work, added more names to check, check first name and last name too, etc. Anyways, It's not working anymore >:(

 

<?php

$firstname = mysql_real_escape_string(htmlentities($_POST['firstname']));

$lastname = mysql_real_escape_string(htmlentities($_POST['lastname']));

$username = mysql_real_escape_string(htmlentities($_POST['username']));

$password = mysql_real_escape_string(htmlentities($_POST['password']));

$confirm = mysql_real_escape_string(htmlentities($_POST['confirm']));

$email = mysql_real_escape_string(htmlentities($_POST['email']));

// prohibited words
$words = array("1", "2", "3", "20 more after this");

// check if username contains prohibited words
if(strpos("$username", "$words")) {
$errors = "<font color='red'>* Username contains prohibited words</font><br>";
}

// check if first name contains prohibited words
if(strpos("$firstname", "$words")) {
$errors = "<font color='red'>* First name contains prohibited words</font><br>";
}

// check if lastname contains prohibited words
if(strpos("$lastname", "$words")) {
$errors = "<font color='red'>* Last name contains prohibited words</font><br>";
}
?>

 

No errors but it seems to not be checking right anymore as the errors do not display. I have not touched anywhere below this section of filtering; every other filter is working right, so display isn't an issue

 

Any help would be appreciated!

Link to comment
https://forums.phpfreaks.com/topic/269875-major-strpos-failure/
Share on other sites

Okay, just use in_array() instead:

if(in_array($username,$words)) {
$errors = "<font color='red'>* Username contains prohibited words</font><br>";
}

 

If that returns an error it must be something to do with what you're passing through to the variables.

Edited by -Karl-
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.