We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19201
    • 1 Posts
    I’m running modx v1.0.3 and using eform v1.4.4.6

    What I would like to do is similar to what I’ve seen on a lot of financial websites when they ask for your credit card and have the message about logging your i.p. address to track down credit card fraud and it displays your i.p. address with the message. I would like to have the i.p. address of the person filling out the form attached to the email that is created when they submit the form.

    Is this something that is even possible with modx and eform? If so, would it be possible for someone to give me a rundown on how to make this happen?

    Thanks in advance to anyone who might be able to help.
    • Mark Hamstra Reply #2, 13 years ago
      With PHP you can access someone’s IP with $_SERVER[’remote_addr’], so you can as well in snippets.

      Make a snippet "ipaddress" and put this in there:
      <?php
      return $_SERVER['remote_addr'];
      


      Now you can call it on your site with [!ipaddress!] or in your eForm report chunk.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 19201
        • 1 Posts
        Quote from: Mark at Apr 29, 2011, 01:05 AM

        With PHP you can access someone’s IP with $_SERVER[’remote_addr’], so you can as well in snippets.

        Make a snippet "ipaddress" and put this in there:
        <?php
        return $_SERVER['remote_addr'];
        


        Now you can call it on your site with [!ipaddress!] or in your eForm report chunk.

        Thank you very much for your quick response. I have created a snippet per your directions. If I put the snippet call into a page it does not display anything. Also, when I put the snippet call into the report chunk it just sent [!ipaddress!] instead of the actual ip addres. I am not sure if I am missing something real basic or not. I am by no means a coding guru.

        Thank you again for your assistance.
        • Mark Hamstra Reply #4, 13 years ago
          Hm, may need to be all uppercase then, sorry tongue

          $_SERVER[’REMOTE_ADDR’]

          If it’s just printing out the call in the eForm chunk I guess it isn’t being processed (I’m too used to Revolution, sorry). You could workaround that by setting a hidden input field with the ip address value, though that is relatively easy to spoof.
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 19201
            • 1 Posts
            uppercase was definitely the answer for fixing the snippet. When I call the snippet on a page it works correctly. Tried a few different things to get it to post with the form but it appears that modx won’t parse a snippet within another snippet. Is it tricky/possible to put the code right in the eform snippet and have it automatically added to the submit email?
            • Here’s my snippet for this
              function getServer( &$fields ){
                  // remote_addr
                  $fields['remote_addr']=$_SERVER['REMOTE_ADDR'];
                  $fields['remote_host']=$_SERVER['REMOTE_HOST'];
                  $fields['user_agent']=$_SERVER['HTTP_USER_AGENT'];
                  //return succes
                  return true;
              }
              ?>
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 19201
                • 1 Posts
                Quote from: sottwell at Apr 29, 2011, 05:37 AM

                Here’s my snippet for this
                function getServer( &$fields ){
                    // remote_addr
                    $fields['remote_addr']=$_SERVER['REMOTE_ADDR'];
                    $fields['remote_host']=$_SERVER['REMOTE_HOST'];
                    $fields['user_agent']=$_SERVER['HTTP_USER_AGENT'];
                    //return succes
                    return true;
                }
                ?>


                Unfortunately I don’t know a whole lot about php. What would I need to do with this function to make it report the ip address so that eForm can include it in the report email?

                Thanks for your help.
                • Create a snippet named getServer with this code. Note that functions need to be named exactly as the parameter in the eform call will specify, and must end with a return true to allow eForm to continue processing. The snippet itself does not need to be named the same as the function; in fact if you have more than one event you want to use you can have multiple functions in a single snippet, as long as each function fulfills the requirements.
                  Add the event function to the eform call:
                  &eformOnBeforeMailSent=`getServer`

                  You can either put the getServer snippet call before the eForm snippet call (the snippet with the function must appear before the eForm snippet call so that the function is defined in PHP’s memory so it’s available to eForm), or you can use the new &runSnippet parameter with the name of your snippet:
                  &runSnippet=`getServer`

                  The fields have been added to the $fields array, so their placeholders are now available for use in your report tpl
                  <strong>IP:</strong> [+remote_addr+]<br />
                  <strong>Host:</strong> [+remote_host+]<br />
                  <strong>User Agent:</strong> [+user_agent+]
                  

                  Note that many servers won’t report their host name, so there probably won’t be any value for that.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 19201
                    • 1 Posts
                    Sottwell and Mark H. thank you both a ton for your help with this. With both of your help I was able to get this going finally. I have found many answers in these forums but this is the first time I have made my own post and I was quite pleased with the quick and helpful responses from you both. Thank you both again very much for your help!!
                      • 24900
                      • 44 Posts
                      Worked great for me although on my server (host gator) I had to change the host to:
                      $fields['remote_host']=gethostbyaddr($_SERVER['REMOTE_ADDR']);