• Hi,

    I need to create a hidden field which records the IP address of the visitor.

    The reason is, I am using this together with a plugin which stores all of the captured CF7 fields efficiently in a database table. It can only record form fields, not email fields, so I cannot use the remote_IP field which CF7 offers.

    So I am trying to work out if I could create a hidden field which uses the PHP variable, $_SERVER[‘HTTP_CLIENT_IP’], or something similar. I am comfortable with simple PHP, but this is beyond my knowledge.

    (I am aware that users can spoof their IP address in this context but this is not a security issues in this case.)

    I don’t necessarily need a complete answer, but any tips or pointers would be really helpful.

    Thanks.

Viewing 15 replies - 1 through 15 (of 18 total)
  • lol lolling

    (@bjornenblog)

    You can use these tags as is. They will not be shows in the form, but will show up in the email you receive after the visitor submits the form.

    [_remote_ip]
    [_user_agent]
    [_url]
    [_date]
    [_time]
    [_post_id]
    [_post_name]
    [_post_title]
    [_post_url]
    [_post_author]
    [_post_author_email]
    [_serial_number]

    I have used them like this, in the “Email” tab.

    Message:
    [your-message]

    Visitor information:
    [_remote_ip]
    [_user_agent]
    [_date]
    [_time]
    [_post_url]

    ozzielisting

    (@ozzielisting)

    OT: remote ip is sending localhost ip what seems to be the problem to this?

    lol lolling

    (@bjornenblog)

    By using

    [_remote_ip]
    [_user_agent]

    You’ll get the IP number of the visitor and all the information. Example:

    11.350.36.11
    Mozilla/5.0 (X11; CrOS x86_64 9765.85.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.123 Safari/537.36

    I find it easiest to put these tags into the “Email” tag as explained in my previous answer.

    Thread Starter Philip Jones

    (@philipmjones)

    Hi,

    Thanks for taking the time to respond to my question and for your suggested solution.

    Unfortunately, the plugin, which I am using to save form data to the database, only looks at the form fields. It does not take account of the email tab.

    I don’t think I can use any of those fields in the ‘form’ tab. Or am I misunderstanding this?

    lol lolling

    (@bjornenblog)

    Hi Philip,

    I apologize for any misunderstanding I might have caused, but I was under the impression that we were talking about CF7 (Contact Form 7) due to the support thread: Support ? Plugin: Contact Form 7 Dynamic Text Extension ? Is it possible to get remote IP address in a hidden field?

    If you’re using CF7 then yes, you can include all of those I mentioned earlier. To achieve what you are looking for, in the “Email” tab = where you define what information you, the site owner, receive in the email after the visitor submits the the form. Example;

    Message:
    [your-message]

    Visitor information:
    [_remote_ip]
    [_user_agent]
    [_date]
    [_time]
    [_post_url]

    To answer your question in a more specific way; there is no need for a hidden field anywhere using CF7 since CF7 per default accepts all of those tags I mentioned.

    lol lolling

    (@bjornenblog)

    Hi again,

    I’m sorry – here’s a solution for you. Since you’re reading all incoming correspondence using the cf7db, try this to make the field hidden.

    [dynamichidden useripnr id:useridnr uneditable “CF7_GET key=’_remote_ip'”]

    That should work.

    lol lolling

    (@bjornenblog)

    Should be:

    [dynamichidden useripnr id:useridnr readonly “CF7_GET key=’_remote_ip’”]

    ozzielisting

    (@ozzielisting)

    I tried it and I still get the local host ip.

    127.0.0.1
    Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36

    lol lolling

    (@bjornenblog)

    Hi,

    Okay, is it the same if trying from your phone?
    127.0.0.1 otherwise indicates a localhost installation. Can you try it on a live production site?

    ozzielisting

    (@ozzielisting)

    Same thing and same with people who contacted me from other countries.

    Thread Starter Philip Jones

    (@philipmjones)

    Hi,

    Thanks again for your help. However I tried the tag and it’s returning an empty value:

    [dynamichidden useripnr id:useridnr readonly “CF7_GET key=’_remote_ip’”]

    I replaced the curly speech marks with ” and ‘ just to be sure. I also tried changing useripnr and useridnr around, as I’m not sure if the difference is intended.

    Can you offer any other suggestions, please?

    lol lolling

    (@bjornenblog)

    Hi,

    If you have Contact Form 7 and Dynamic Text plugin installed, then the bracket I gave you as an example;

    [dynamichidden useripnr id:useridnr readonly “CF7_GET key=’_remote_ip’”]

    Then that works. It works for me on six different sites with different themes.

    lol lolling

    (@bjornenblog)

    [dynamichidden ruip readonly “CF7_get_post_var key=’_remote_ip'”]

    Try using it that way. “ruip” is for remote user ip.

    Hi @bjornenblog

    Have the same issue as Philip Jones unfortunately.

    Also need to add these fields in the Form tab – not the Message tab to enable the info to be sent to Zapier using “https://www.ads-software.com/plugins/cf7-to-zapier/”. Dynamic text in the message field is not sent. They have to be a hidden form field.

    Tried [dynamichidden ruip readonly “CF7_get_post_var key=’_remote_ip’”] and [dynamichidden useripnr id:useridnr readonly “CF7_GET key=’_remote_ip’”] to the form however nothing is sent.

    How can I do that? Being able to do this would enable support for Zapier.

    • This reply was modified 6 years, 9 months ago by appscaptain. Reason: Clarification

    I figured out why this wasn’t working.

    When you cut and paste the code in, it changes the quotes from single quotes to inverted apostrophes and a similar thing with the double quotes.

    I’ve got the hidden fields in my forms now, but when I read the HTML source the variables are empty (i.e. no IP address). Any ideas what I’m missing?

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Is it possible to get remote IP address in a hidden field?’ is closed to new replies.