PHP IP Allow

Discussion in 'PHP' started by Snarr, Dec 30, 2008.

  1. #1
    I was wondering how to allow IP addresses to view my page. I want to make a list of IPs that are allowed, and all others will be blocked. I also would like to call on that PHP file from Flash, and if the IP is allowed, the Flash will go to a specified frame number. Does anyone have any idea on how to do this?

    EDIT: Here is my current code:
    <?
    $allow[0]="0.0.0.0"; 
    if (in_array($_SERVER['REMOTE_ADDR'],$allow)) 
    { 
    echo "Welcome" ;
    }
    else echo "You are not authorized to view this page."
    ?>
    PHP:

     
    Snarr, Dec 30, 2008 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Should work just fine.
    <?php
    
    $allowed = array('127.0.0.1');
    
    if ( !in_array($_SERVER['REMOTE_ADDR'], $allowed) )
    	die('You\'re not allowed here.');
    	
    /* otherwise put the rest of your code here */
    // _stuff(); more_stuff($var);
    PHP:
    Makes a code for easier reading, after the die statement just put any code you want if they're valid.

    Could you use a AJAX request via Flash (not familar with flash personally) to get the page, although I fear this could be easily spoofed.
     
    Danltn, Dec 30, 2008 IP
  3. Snarr

    Snarr Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I don't know. I just want to call the PHP file from Flash and if the user is allowed, the Flash goes to frame 2. If not, frame 3.
     
    Snarr, Dec 30, 2008 IP