SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to encorporate this?

    Hello,

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

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

    $address 'BaDaDdReSs@pr0n_site.xxx';

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

    Into my current checking PHP:

    PHP Code:
    <?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

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    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.



    Code PHP:
    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>';
    }
    ?>
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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');'

    PHP Code:
    session_start();
     <?php
    if(isset($_POST["captcha"]) && $_SESSION["captcha"]==$_POST["captcha"])
    {
     
        
    $blacklisted = array('email@email.com');
     
        
    $address 'email@email.com';
     
        if( !
    in_arraystrtolower($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

  4. #4
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bump

  5. #5
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:


    Quote Originally Posted by sphinxy View Post
    bump

    Just an fyi
    :

    Bumping threads is discouraged.

    If your thread hasn't received any answers, don't bump it.
    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


  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by webdev1958 View Post
    Off Topic:



    Just an fyi
    :

    Bumping threads is discouraged.

    Perhaps do it more discretely next time
    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?

  7. #7
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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.

  8. #8
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I'm getting there,

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

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

    Code:
    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

  9. #9
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by sphinxy View Post
    Thanks, I'm getting there,

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

    Code:
    Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/sphinxy/public_html/index.php on line 10
    What's on line 10 right now?

    and this:

    Code:
    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.

    Code:
    <?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>
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  10. #10
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if( !in_arraystrtolower($email), $blacklist ) ) { 
    That was line 10.

    Many thanks

  11. #11
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by sphinxy View Post
    PHP Code:
    if( !in_arraystrtolower($email), $blacklist ) ) { 
    That was line 10.
    Check your variable names.

    Going by the code above:
    $email and $address don't match.
    $blacklist and $blacklisted don't match.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •