How to display the content only to the allowed IP address [closed]

I have tried your code and its working fine for me.

<?php  
    $allow = array("xxx.xx.xxx.xxx","xxx.xx.xxx.xxx"); //allowed IPs

    if(!in_array($_SERVER['REMOTE_ADDR'], $allow) && !in_array($_SERVER["HTTP_X_FORWARDED_FOR"], $allow) && !in_array($_SERVER["HTTP_CLIENT_IP"], $allow))  {  ?>
        <div class="enclose comn-pg">
        <h1 align="center" style="padding:10% 0;">Access denied.  This page is accessible only to customers.</h1>
        </div>                  


    <?php } else { ?>
        <div class="enclose comn-pg">
        <div id="primary">
        <div id="content" role="main">

        <?php while ( have_posts() ) : the_post(); ?>

        <?php get_template_part( 'content', 'page' ); ?>

        <?php comments_template( '', true ); ?>

        <?php endwhile; // end of the loop. ?>

        </div><!-- #content -->
        </div><!-- #primary -->
        </div>

    <?php
    }
?>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)