Support Forums
PHP Array Help - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: PHP Array Help (/showthread.php?tid=5125)



PHP Array Help - Dutchcoffee - 03-01-2010

Hi,

I'm trying to use an array to pick out the "blacklisted" words from being used.

I'm currently trying to use this...

PHP Code:
$not_allowed = array("root","www","www2","ww3","admin","staff","dev","mail","web","cpanel","webmail","whm","host","ww2","members","member"); 

And to execute this, I'm using...

PHP Code:
if(in_array($not_allowed))
{
    
$_SESSION['error'] = $not_allowed_error;


What I want, is if anyone types any of those words in the specified text field, it will give them an error, but it's not picking them out for some reason.

Thanks.


RE: PHP Array Help - Omniscient - 03-01-2010

You need the $needle part of the in_array() function.

bool in_array ( mixed $needle , array $haystack [, bool $strict ] )

So you'll do something like this.

PHP Code:
$input $_POST['input'];
if(
in_array($input$not_allowed))
{
    
$_SESSION['error'] = $not_allowed_error;




RE: PHP Array Help - Dutchcoffee - 03-01-2010

Wow!! Thank you so much! It works perfect. Smile

(rep+)