www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > PHP

    PHP Discussion and technical support for using and deploying PHP based websites.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-20-2009, 11:37 AM
    comptech520 comptech520 is offline
    FOH Audio Engineer
     
    Join Date: Apr 2005
    Location: Behind my DiGiCo SD7 Console
    Posts: 823
    Make it so only specified IP address can see site

    In PHP, how can I make it so only a specified IP address can see a website? All other users will be directed to another website?
    __________________
    Registered Linux User: #463250
    -----------------
    HELPFUL LINKS
    PHP - http://www.php.net
    Website Color Schemer - http://www.colorschemer.com/online.html
    Reply With Quote
      #2  
    Old 11-20-2009, 02:20 PM
    NogDog's Avatar
    NogDog NogDog is online now
    High Energy Magic Dept.
     
    Join Date: Aug 2004
    Location: Ankh-Morpork
    Posts: 14,009
    PHP Code:
    <?php
    $allowedIps
    = array(
       
    '1.2.3.4',
       
    '1.2.4.6'
    );
    if(!
    in_array($allowedIps, $_SERVER['REMOTE_ADDR']))
    {
       
    header('Location: http://some.other.site/');
       exit;
    }
    ?>
    <!-- rest of page -->
    __________________
    "That's what the gods are! An answer that will do! Because there's food to be caught and babies to be born and life to be lived and so there is not time for big, complicated, and worrying answers! Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." -- from Nation, by Terry Pratchett
    freelancer.internet.com
    Email me
    Reply With Quote
      #3  
    Old 11-21-2009, 07:42 AM
    SrWebDeveloper's Avatar
    SrWebDeveloper SrWebDeveloper is offline
    Registered User
     
    Join Date: Jul 2009
    Location: Falls Church, Va.
    Posts: 381
    OP: Please be informed - if the visitor comes through a proxy or firewall on their end their WAN IP might be the same as anyone else on their LAN. So you might intend to block one user but might end up blocking many sharing that IP. Plus if your filter allows wildcards to ban ranges, one typo and you could ban an entire class C, B or huge block of unintended addresses with one unnoticed typo. And even proxy servers can be used to bypass an IP ban anyway unless you implement an anti-blocking script. In short, there are a few notable potential headaches if this kind of policy is not applied sensibly and carefully.

    -jim
    Reply With Quote
      #4  
    Old 11-21-2009, 12:05 PM
    NogDog's Avatar
    NogDog NogDog is online now
    High Energy Magic Dept.
     
    Join Date: Aug 2004
    Location: Ankh-Morpork
    Posts: 14,009
    Quote:
    Originally Posted by SrWebDeveloper View Post
    OP: Please be informed - if the visitor comes through a proxy or firewall on their end their WAN IP might be the same as anyone else on their LAN. So you might intend to block one user but might end up blocking many sharing that IP. Plus if your filter allows wildcards to ban ranges, one typo and you could ban an entire class C, B or huge block of unintended addresses with one unnoticed typo. And even proxy servers can be used to bypass an IP ban anyway unless you implement an anti-blocking script. In short, there are a few notable potential headaches if this kind of policy is not applied sensibly and carefully.

    -jim
    I was under the impression from the original post that the OP wanted to whitelist one or a small number of IPs, not blacklist a limited number or range of IP addresses.

    In either case, this could also be handled at the web server level such as limiting access to a directory via a .htaccess entry (if Apache), though I'd have to do a little Googling to come up with the syntax for that.
    __________________
    "That's what the gods are! An answer that will do! Because there's food to be caught and babies to be born and life to be lived and so there is not time for big, complicated, and worrying answers! Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." -- from Nation, by Terry Pratchett
    freelancer.internet.com
    Email me
    Reply With Quote
      #5  
    Old 11-24-2009, 02:26 PM
    SrWebDeveloper's Avatar
    SrWebDeveloper SrWebDeveloper is offline
    Registered User
     
    Join Date: Jul 2009
    Location: Falls Church, Va.
    Posts: 381
    Quote:
    Originally Posted by NogDog View Post
    I was under the impression from the original post that the OP wanted to whitelist one or a small number of IPs, not blacklist a limited number or range of IP addresses.
    Understood, the implications I listed work in reverse, too, i.e. you can let a whole LAN segment in if their caching proxy is bound to a single IP, for example. The main point is using IP's is subject to consequences, so be aware and carefully setup any filters. That's all.

    -jim

    Last edited by SrWebDeveloper; 11-24-2009 at 02:28 PM. Reason: Fixed the quote tag
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 03:45 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.