We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4266
    • 70 Posts
    Would it be fine to set up this snippet to work with MODx?

    How to set IPs and redirect pages direct on the page (not in the snippet code)?

    //*************************************************************
    // Snippet Name:  IPFeeder
    // Purpose:       Feed content depending on IP Address
    // Author:        sniperx [email protected]
    //
    // History:       11 December 2004 - Original Release
    //
    // Use:           Build and save snippet as IPFeeder,
    //                add {!IPFeeder!] to pages you want to
    //                detect IP Addresses.
    //
    // LICENSE:       For use only within LEGALLY Licensed 
    //                copies of Etomite CMS.
    //                You are free to amend this snippet for
    //                your own needs. Please consider sharing
    //                any modifications with the Etomite community.
    //**************************************************************
    
    // Add IP Addresses to Detect.
    $ips = array('192.168.1.1','192.168.1.2','192.168.1.3','192.168.1.4');
    
    // Page to Redirect To Upon Detection.
    $redirect = "/stealth.html";
    $retval="";
    
    if (isSet($_SERVER)) {
       if (isSet($_SERVER["HTTP_X_FORWARDED_FOR"])) {
          $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
       } 
       elseif (isSet($_SERVER["HTTP_CLIENT_IP"])) {
          $retval = $_SERVER["HTTP_CLIENT_IP"];
       } 
       else {
          $retval = $_SERVER["REMOTE_ADDR"];
       }
    } 
    else {
       if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
          $retval = getenv( 'HTTP_X_FORWARDED_FOR' );
       } 
       elseif ( getenv( 'HTTP_CLIENT_IP' ) ) {
          $retval = getenv( 'HTTP_CLIENT_IP' );
       } 
       else {
          $retval = getenv( 'REMOTE_ADDR' );
       }
    }
    
    if (in_array($retval, $ips)) {
       header("Location: $redirect");
    }