CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Get IP Address and Host name in fields of contribution page
Pages: [1]

Author Topic: Get IP Address and Host name in fields of contribution page  (Read 730 times)

Tchiot Galopin

  • I’m new here
  • *
  • Posts: 13
  • Karma: 0
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 7.12
  • MySQL version: 5.1.44
  • PHP version: 5.3.3.7
Get IP Address and Host name in fields of contribution page
October 05, 2011, 01:11:25 pm
    Hello,

    For legal reasons, the government asked us to keep a record of the IP address and host name of our contributors in order to help trace payment history.

    Thus, we created two additional custom fields (one for the IP and one for the host name) that we have added to the custom profile associated with our contribution page.

    We'd like, now that these two fields be pre-filled (and, if possible, non-editable by the user), with the users correspondent data.

    I assume that these informations will have to be collected through these two queries:

Quote
<?php
if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"] != ""){
     // for proxy
     $IP = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
}else{
     // for normal user
     $IP = $HTTP_SERVER_VARS["REMOTE_ADDR"];
}
?>

Quote
<?php
if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"] != ""){
     // for proxy
     $host = @gethostbyaddr($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]);
}else{
     // for normal user
     $host = @gethostbyaddr($HTTP_SERVER_VARS["REMOTE_ADDR"]);
}
?>

    How can I then link <?php echo $IP; ?> and <?php echo $host; ?> to « value =" " » of my two <input> fields? In addition, how can we make sure that these two fields are not editable (however they can be visible to public users or not)?

    Thank you in advance for your help ...  :-\
« Last Edit: October 05, 2011, 01:16:23 pm by Tchiot Galopin »

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Get IP Address and Host name in fields of contribution page
October 05, 2011, 02:06:46 pm
I think the recommended drupal way to get the IP is

http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/ip_address/7

Which is much like your first one.

You are looking to write a small module implementing a CiviCRM hook - probably the
buildForm hook to add the fields as hidden fields & the
postProcess hook will allow you to populate them.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Get IP Address and Host name in fields of contribution page

This forum was archived on 2017-11-26.