I'm actually testing a website with Drupal 7.

I am searching a way to get the visitors' IP, when they submit a new node; the users can also be not logged-in, as anonymous users are allowed to submit new content.

I can't find a module to do that, and I don't know how to use hooks or PHP to achieve this.

What should I do?

  • what do you want to do with the visitor IP? Save it somewhere? Render it on the node page or what? Commented Apr 24, 2012 at 18:42
  • no, I only need this for some legal stuff ... Just save it in mysql, so I can see "who" write a node (without register).
    – user117283
    Commented Apr 24, 2012 at 21:03

3 Answers 3


I haven't found a module which does this yet. You can do these steps:

  1. Create a text field named ip_address
  2. Manage display: make the field hidden
  3. Use Display Suite or a custom hook (or even CSS) to hide the field when filling out the form
  4. Create a Rule on event "Before saving content"
  5. Set a condition of content type: your content type
  6. Set a condition of Data comparison: [node:is-new], Data value: True (check the checkbox)
  7. Set an action of Set a data value, and set the field to be:

PHP Code

  print ip_address();

That should do it.

You could also accomplish this by creating a module and using some hooks

  • Work great ! Of course, need PHP module from Core enabled. Thank you.
    – user117283
    Commented Apr 24, 2012 at 23:50
  • 3
    You can also use the [current-user:ip-address] token in the field default, then hide the field as you suggest above. Commented Jul 30, 2013 at 20:39
  • 1
    One can also use comment:hostname, such that the PHP module is not acquired.
    – Jeroen
    Commented Apr 9, 2017 at 14:18

There is a simple way to do this. Install the Computed Field module.

Add a computed filed (for IP address) to your content type and add the following line in Computed Code (PHP) textarea to get current ip address of the author

$entity_field[0]['value'] = ip_address();

That's it.You will get submitted author ip address. No need to install any other modules


I wrote simple module for saving author ip address. With this module you can add field to content type, which filled with ip address author on node creation.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.