We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25273
    • 13 Posts
    Hi,

    I have a problem where I am trying to route visitors through different page flows on our website dependent upon their IP address.
    I have spent three days looking at how to achieve this, but I can’t get my head around it.

    For instance:

    User A has an IP address of XXXXXX, I want their route to flow like this:
    Page 1 (click on hyperlink to page 2) ===> Page 2.ver1 (click on hyperlink to page 3) ===> Page 3

    User B has an IP address of YYYYYY, I want their route to flow like this:
    Page 1 (click on hyperlink to page 2) ===> Page 2.ver2 (click on hyperlink to page 3) ===> Page 3

    I have searched for plugins that may do this kind of thing but have drawn a blank.

    As I see it, I need to be able to:

    • Retrieve the visitor’s IP address
    • Compare that address against a list of IP ranges that then returns a value (i.e. A, B, C etc.)
    • Then route to one of a number of different pages depending on the return value



    I don’t know if anyone can point me in the right direction as to how I might be able to do this type of thing?


    Our Setup
    MODx version 1.0.3
    Version codename rev 6653
    phpInfo() View
    Access permissions Enabled
    Server Time 12:46:32
    Local Time 12:46:32
    Server offset 0 h
    Database name domain_com_modx
    Database server 127.0.0.1
    Database Version 5.0.92-community-log
    Database Charset latin1
    Database Collation Charset latin1_swedish_ci
    Table prefix modx_
    MODX_BASE_PATH /home/public_html/
    MODX_BASE_URL /
    MODX_MANAGER_URL http://www.domain.com/manager/
    MODX_MANAGER_PATH /home/public_html/manager/
    MODX_SITE_URL http://www.domain.com/
      • 21838
      • 284 Posts
      I have a client site running such a snippet. I currently can’t set this open-source, if client says yes to this, I will do that in near future.
        MODX Free Template Base: MODX-Boilerplate | my blog (lots of MODX stuff) | my gitHub (translations) | MODX User Groups Germany (Facebook)
        • 20413
        • 2,877 Posts
        You want to write a plugin or (DUH!) use a SNIPPET!

        <?php
        $user = $_SERVER["REMOTE_ADDR"];
            
        $check1 = strpos($user, 'XXX.XXX.XX.XX'); //Replace with IP
        $check2 = strpos($user, 'XXX.XXX.XX.XX');
          
        if ($check1 !== false){ 
            $modx->sendForward(1); //resource id 1 
        } elseif ($check2 !== false){ 
            $modx->sendForward(2);
        }
        



        ----
        http://modxcms.com/forums/index.php/topic,34174.msg207863.html#msg207863
        http://modxcms.com/forums/index.php/topic,34341.0.html
          @hawproductions | http://mrhaw.com/

          Infograph: MODX Advanced Install in 7 steps:
          http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

          Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
          http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
          • 25273
          • 13 Posts
          Thanks for the replies laugh

          I’ve been unavoidably away for the past couple of weeks, but I’ll now take another look at this. Thanks for the pointer.

            • 21838
            • 284 Posts
            Quote from: novolo at Jun 08, 2011, 05:06 AM

            I have a client site running such a snippet. I currently can’t set this open-source, if client says yes to this, I will do that in near future.
            This will released soon for the community from Bruno17 and should go to extra’s section then. Functionality is like a newspaper-paywall.
              MODX Free Template Base: MODX-Boilerplate | my blog (lots of MODX stuff) | my gitHub (translations) | MODX User Groups Germany (Facebook)
              • 25273
              • 13 Posts
              Just an update in case anyone is looking to get each visitor’s location.

              I have implemented to free MaxMind Geolite utility. I found the following post most helpful in applying this:
              http://modxcms.com/forums/index.php?topic=50853.0

              Thank you for your feedback and suggestions.
                • 3749
                • 24,544 Posts
                Quote from: mrhaw at Jun 08, 2011, 05:28 AM

                You want to write a plugin or (DUH!) use a SNIPPET!

                <?php
                $user = $_SERVER["REMOTE_ADDR"];
                    
                $check1 = strpos($user, 'XXX.XXX.XX.XX'); //Replace with IP
                $check2 = strpos($user, 'XXX.XXX.XX.XX');
                  
                if ($check1 !== false){ 
                    $modx->sendForward(1); //resource id 1 
                } elseif ($check2 !== false){ 
                    $modx->sendForward(2);
                }
                


                For anyone using this snippet, I would recommend this instead (default case keeps from hanging the user out to dry):

                <?php
                $user = $_SERVER["REMOTE_ADDR"];
                
                /* if you are behind a proxy server, you'd probably want this instead:
                         $user =   $_SERVER['HTTP_X_FORWARDED_FOR'];
                */
                    
                switch ($user ) {
                    case 'xx.xxx.xx.xx':    //Replace with IP
                        $modx->sendForward(1); //resource id 1 
                        break;
                   
                   case 'xx.xxx.xx.xx' // Replace with IP
                        $modx->sendForward(2);
                        break;
                
                   default:
                        $modx->sendForward(3);
                        break;
                }  
                
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 25273
                  • 13 Posts
                  The advantage of the MaxMind Geolite utility is that they make available and update an IP address to country code database. Therefore, I did not have to worry about individual, or ranges of, IP addresses. Thus, the code can look something like this:


                      
                  switch ($country ) {
                      case 'US':    //
                          $modx->sendForward(1); //resource id 1 
                          break;
                     
                     case 'GB' //
                          $modx->sendForward(2);
                          break;
                  
                     default:
                          $modx->sendForward(3);
                          break;
                  }  
                  


                  Thanks, to everyone for their input on this.