Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Can I save part of an IP address?

  • ymca
  • ymca's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
4 years 2 weeks ago #195883 by ymca
Can I save part of an IP address? was created by ymca
Hi,

Instead of saving the entire IP number, can I save just the start so I will not break the privacy laws?
I have seen in matomo that they can save just IP number of the country the users are coming from.
Can we do it in LimeSurvey?

LS Version 4.2+
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago - 4 years 2 weeks ago #195896 by tpartner
Replied by tpartner on topic Can I save part of an IP address?
As far as I know, there is no way to detect the IP address directly with JavaScript but you should be able to make an AJAX call to a PHP script the returns the IP address and then parse that and load it into a short-text question.

Something like this in the source of the short-text:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // AJAX call to the PHP file
    $.get('https://pathTo/returnIP.php', function(data) {
 
      // Create an array of the IP address character sets
      var ipArray = data.split('.');
 
      // Load the text element with the first character set in the array
      $('input:text', thisQuestion).val(ipArray[0]);
    });
    });
</script>

And, maybe something like this in the PHP file but you should research this to see if there is a more secure method:

Code:
<?php
 
  $ip = $_SERVER['REMOTE_ADDR']?:($_SERVER['HTTP_X_FORWARDED_FOR']?:$_SERVER['HTTP_CLIENT_IP']);
 
  echo $ip;
 
 
?>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 2 weeks ago by tpartner.
The following user(s) said Thank You: ymca
The topic has been locked.
  • ymca
  • ymca's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
4 years 2 weeks ago #195908 by ymca
Replied by ymca on topic Can I save part of an IP address?
Thanks.
How do they say? "It's above my pay grade."
I mean It's too difficult for me :S
Is it a "feature request-able" thing that I can post (an option that lets the survey creator choose if to collect full IP or part of it to the survey)?

LS Version 4.2+
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago #195916 by holch
Replied by holch on topic Can I save part of an IP address?

Is it a "feature request-able" thing that I can post (an option that lets the survey creator choose if to collect full IP or part of it to the survey)?

Of course you can, but there are other feature requests that I would consider far more important waiting for years now, so I think chances are low that this will be implemented as a feature. Maybe someone creates a Plugin for it.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The following user(s) said Thank You: DenisChenu, ymca
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago #196002 by DenisChenu
Replied by DenisChenu on topic Can I save part of an IP address?

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: ymca
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose