How to encorporate this?

Hello,

I’m really new to PHP and I would like to be shown how to implement:

$blacklisted = array( lower-case blocked addresses here );

$address = 'BaDaDdReSs@pr0n_site.xxx';

if( in_array( strtolower($email), $blacklist ) {
     // block
} else {
     / allow
}

Into my current checking PHP:

<?php session_start() ?>
<?php
if(isset($_POST["captcha"]))
if($_SESSION["captcha"]==$_POST["captcha"])
{
require('process.php');
}
else
{
$incorrect = "<div id=\\"captchatext\\" >That code was incorrect, please try again.</div>";
}
?>

What I want to occur, is it to check the blacklist, then, if it is clean, for it to require process.php.

Many thanks

A went ahead and made a few adjustments.

The session_start() function doesn’t have to be in its own set of PHP tags. You were also missing the ending semicolon.

You can put multiple conditions in an if-statement by using && or || operators.

You can nest if-statements (put if-statements inside of if-statements). Use tab to indent code blocks that you place inside of other code blocks.

Typically, the action you would expect most to happen would be first (the “allow” result instead of the “block” result).

You can use echo to spit out text as you go.

Typically, when writing HTML in a string, it’s easier to use a single-quote string, rather than a double-quote string. That way, there are fewer characters to escape, which usually leads to fewer mistakes.

session_start();

if(isset($_POST["captcha"]) && $_SESSION["captcha"]==$_POST["captcha"])
{

    $blacklisted = array( lower-case blocked addresses here );

    $address = 'BaDaDdReSs@pr0n_site.xxx';

    if( !in_array( strtolower($email), $blacklist ) {
         //allow
         require('process.php');
    } else {
         //block
         echo '<p>that address is not allowed</p>';
    }  

}
else
{
    echo '<div id="captchatext">That code was incorrect, please try again.</div>';
}
?> 

Many thanks,

I was getting an expected ‘{’ here ‘if( !in_array( strtolower($email), $blacklist ) {

then when corrected, an unexpected t require here ‘require(‘process.php’);’

session_start();
 <?php
if(isset($_POST["captcha"]) && $_SESSION["captcha"]==$_POST["captcha"])
{
 
    $blacklisted = array('email@email.com');
 
    $address = 'email@email.com';
 
    if( !in_array( strtolower($email), $blacklist ) {
         //allow
         require('process.php');
    } else {
         //block
         echo '<p>that address is not allowed</p>';
    }  
 
}
else
{
    echo '<div id="captchatext">That code was incorrect, please try again.</div>';
}
?>

Many thanks

bump

Off Topic:


Just an fyi
: :slight_smile:

Bumping threads is discouraged.

                           If your thread hasn't received any answers, [B]don't bump it.[/B]

Do not revive old threads by posting on them and getting them back to the first position of the list. Those discussions were finished or didn’t get enough attention in the first place.

Perhaps do it more discretely next time :slight_smile:

That’s correct. sphinxy, you can ‘bump’ your post by giving some more info, for example about further tests you’ve done, that might help people to anwser your question.
In this particular case, it was not clear (to me at least) that you were still asking a question in your post #3.

What is the exact error you’re getting?

if( !in_array( strtolower($email), $blacklist ) ) {

Just missing a closing bracket as indicated, I think.

As a general guide – when trying to chase this error down, simply start at the left and count the number of opening brackets - you should then have the same number of closing ones. You had 3 and 2.

Thanks, I’m getting there,

When form has been filled in and submitted, this shows:

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/sphinxy/public_html/index.php on line 10

and this:

echo '<div id="captchatext">That code was incorrect, please try again.</div>';

Displays on the top of the page all the time, even before the page has been submitted.

Many thanks

What’s on line 10 right now?

and this:

echo '<div id="captchatext">That code was incorrect, please try again.</div>';

Displays on the top of the page all the time, even before the page has been submitted.

Then you will have the string as a variable and echo it out later in your HTML within its own set of PHP tags.


<?php

$errorMsg = '<div id="captchatext">That code was incorrect, please try again.</div>';

?>

<!-- code, code, and more code -->

<p>blah blah<p><?php echo $errorMsg; ?><p>more blah blah</p>
if( !in_array( strtolower($email), $blacklist ) ) { 

That was line 10.

Many thanks

Check your variable names.

Going by the code above:
$email and $address don’t match.
$blacklist and $blacklisted don’t match.