[NEED HELP] Echo file, based on condition

Discussion in 'PHP' started by surfnearnzone, Aug 2, 2012.

  1. #1
    I want to do something like this:

    <?php
    $ipaddress = $_SERVER["REMOTE_ADDR"];
    $content = file_get_contents('adfly.php');
    
    if ($ipaddress=='14.98.14.230')
        {
        echo $content;
        }
    ?>
    Code (markup):
    The purpose is to show ads only to a specific group of people and turn of ads for others.

    Please help
     
    Solved! View solution.
    surfnearnzone, Aug 2, 2012 IP
  2. artus.systems

    artus.systems Well-Known Member

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #2
    Code looks ok, btw what is the problem
     
    artus.systems, Aug 2, 2012 IP
  3. surfnearnzone

    surfnearnzone Well-Known Member

    Messages:
    1,492
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #3
    it doesn't seem to be working

     
    surfnearnzone, Aug 2, 2012 IP
  4. surfnearnzone

    surfnearnzone Well-Known Member

    Messages:
    1,492
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    165
    #4
    anyone available?? it is urgent!!
     
    surfnearnzone, Aug 2, 2012 IP
  5. #5
    There doesn't really seem to be anything wrong with the code as far as I can tell. The only things that may be preventing it from working would be that you don't have permissions to read the file or there is something wrong in adfly.php. If you could post the server error_logs and/or the contents of the adfly.php file, that would make it much easier to debug. However, if you are looking to execute the adfly.php instead of just write the contents, you may want to go with something like this:

    if ($_SERVER['REMOTE_ADDR'] == '14.98.14.230') {
        require_once 'adfly.php';
    }
    PHP:
     
    Thorlax402, Aug 2, 2012 IP
  6. michaelh73

    michaelh73 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yeah there might be something wrong with your adfly.php
     
    michaelh73, Aug 3, 2012 IP