ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Make comment form show for Certain IP Adress Only

May 05, 2009 5:44pm

Subscribe [2]
  • #1 / May 05, 2009 5:44pm

    Luke101

    10 posts

    Hello,
    is there a way to make my comment form show for certain IP Blocks? I have a list of IP adresses I would like to block from seeing my comment form. Would you have sample code.

  • #2 / May 06, 2009 7:25am

    silenz

    1651 posts

    Well, a basic example using PHP (you need to allow PHP for the template) could go along the lines of this:

    <?php
    global $IN;
    $show = TRUE;
    $block = array("195.195.", "69.", "192.168.0.2"); // Array of IP-addresses to be blocked
    foreach ($block as $ip)
    {
        if ( strncmp($IN->IP, $ip, strlen($ip)) == 0 ) 
         {
            $show = FALSE;
            break;
         }
    }
    
    if ($show === TRUE)
    {
    ?>
    {exp:comment:form}
    
    {/exp:comment:form}
    <?php
    }
    ?>
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases