PDA

View Full Version : Guide to storing the user IP address.



Steffen Buschkemper
June 8, 2013, 06:08 PM
Hello Juergen and all who need this feature,

Because of this thread here (http://www.flynax.com/forum/showthread.php?1227-Storing-IP-address-for-registration-listing-creation-and-comments-plugin&p=5210&viewfull=1#post5210) i present today this "little" guide.

Due to legal situations in some countries is the storing of User-IP addresses an important evidentiary.
Missing evidentiary can be expensive for website operators.
For example applies in Germany the "liability for interference".


Storing the IP Address at the registration process

The result you can see in the follow picture

540

Now let us start.

PART 1

Login into the Admin Panel and go to Common -> Database
Paste the follow SQL query



ALTER TABLE `{sql_prefix}accounts` ADD `User_IP` INT(11) UNSIGNED NOT NULL


and press the button "Go".

Finally paste the following SQL query to insert the phrase "User-IP" for table header (ext_userip). Language is english.



INSERT INTO `{sql_prefix}lang_keys` (`ID`, `Code`, `Module`, `Key`, `Value`, `Plugin`, `Status`) VALUES (NULL, 'en', 'ext', 'ext_userip', 'User-IP', '', 'active')


and press the button "Go".

PART 2

Open admin => tpl => controllers => accounts.tpl

Find the follow code



{name: 'Username', mapping: 'Username', type: 'string'},
{name: 'Name', mapping: 'Name', type: 'string'},
{name: 'Mail', mapping: 'Mail', type: 'string'},
{name: 'Status', mapping: 'Status'},
{name: 'Type', mapping: 'Type', type: 'string'},
{name: 'Type_name', mapping: 'Type_name', type: 'string'},
{name: 'thumbnail', mapping: 'thumbnail', type: 'string'},
{name: 'fields', mapping: 'fields', type: 'string'},
{name: 'ID', mapping: 'ID', type: 'int'},
{name: 'Date', mapping: 'Date', type: 'date', dateFormat: 'Y-m-d H:i:s'}



and change as follow



{name: 'Username', mapping: 'Username', type: 'string'},
{name: 'Name', mapping: 'Name', type: 'string'},
{name: 'Mail', mapping: 'Mail', type: 'string'},
{name: 'Status', mapping: 'Status'},
{name: 'Type', mapping: 'Type', type: 'string'},
{name: 'Type_name', mapping: 'Type_name', type: 'string'},
{name: 'User_IP', mapping: 'User_IP', type: 'string'}, /*New data definition for User-IP field*/
{name: 'thumbnail', mapping: 'thumbnail', type: 'string'},
{name: 'fields', mapping: 'fields', type: 'string'},
{name: 'ID', mapping: 'ID', type: 'int'},
{name: 'Date', mapping: 'Date', type: 'date', dateFormat: 'Y-m-d H:i:s'}


Next find the follow code



{
header: lang['ext_type'],
dataIndex: 'Type_name',
width: 13/*,
renderer: function(val, obj, row){
var out = '<a target="_blank" ext:qtip="'+lang['ext_click_to_edit']+'" href="'+rlUrlHome+'index.php?controller=account_types&action=edit&type='+row.data.Type+'">'+val+'</a>';
return out;
}*/
},



and change as follow



{
header: lang['ext_type'],
dataIndex: 'Type_name',
width: 13/*,
renderer: function(val, obj, row){
var out = '<a target="_blank" ext:qtip="'+lang['ext_click_to_edit']+'" href="'+rlUrlHome+'index.php?controller=account_types&action=edit&type='+row.data.Type+'">'+val+'</a>';
return out;
}*/
},{
header: lang['ext_userip'], /*Table header for User-IP field*/
dataIndex: 'User_IP', /*User_IP Data Field*/
width: 13,
},


Save and close the File.

PART 3

Open includes => classes => rlAccount.class.php

Find the follow code



// step 1
$data = array(
'Type' => $account_type_key,
'Username' => $profile['username'],
'Own_address' => $profile['location'],
'Password' => md5($profile['password']),
'Password_tmp' => $account_types[$type_id]['Email_confirmation'] ? $profile['password'] : '',
'Lang' => strtolower(RL_LANG_CODE),
'Mail' => $profile['mail'],
'Date' => 'NOW()'
);


and change as follow



function getClientIp()
{
$result = null;
$ipSourceList = array(
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR'
);
foreach ($ipSourceList as $ipSource) {
if (isset($_SERVER[$ipSource])) {
$result = $_SERVER[$ipSource];
break;
}
}
return $result;
}
$user_ip = getClientIp();

// step 1 incl. new User-IP
$data = array(
'User_IP' => ip2long($user_ip),
'Type' => $account_type_key,
'Username' => $profile['username'],
'Own_address' => $profile['location'],
'Password' => md5($profile['password']),
'Password_tmp' => $account_types[$type_id]['Email_confirmation'] ? $profile['password'] : '',
'Lang' => strtolower(RL_LANG_CODE),
'Mail' => $profile['mail'],
'Date' => 'NOW()'
);


Save and close the File.

PART 4

Open admin => controllers => accounts.inc.php

Find the follow code



$sql = "SELECT SQL_CALC_FOUND_ROWS `ID`, CONCAT(`First_name`, ' ', `Last_name`) AS `Name`, `Username`, `Type`, `Status`, `Mail`, `Date`, `Photo`, ";


and change as follow



$sql = "SELECT SQL_CALC_FOUND_ROWS `ID`, CONCAT(`First_name`, ' ', `Last_name`) AS `Name`, `Username`, `Type`, INET_NTOA(`User_IP`) AS `User_IP`, `Status`, `Mail`, `Date`, `Photo`, ";


Save and close the File.

OK these were the parts to store the user ip during the registration process.
Next part is "Storing the User-IP address when add comments"

Best regards
Steffen

Steffen Buschkemper
June 10, 2013, 04:20 AM
Storing the User-IP address when add comments

Please note this feature will only work with installed listing comments plugin!

The result you can see in the follow picture

543

Login into the Admin Panel and go to Common -> Database
Paste the follow SQL query



ALTER TABLE `{sql_prefix}comments` ADD `User_IP` INT(11) UNSIGNED NOT NULL AFTER `Author`


and press the button "Go".

INFO The phrase for table header we do not need adding anymore, if the upper part "Storing the IP Address at the registration process" was made.

PART 2

Open plugins => comment => admin => comment.tpl

Find the follow code



{name: 'ID', mapping: 'ID', type: 'int'},
{name: 'Title', mapping: 'Title', type: 'string'},
{name: 'Author', mapping: 'Author', type: 'string'},
{name: 'Listing_type', mapping: 'Listing_type', type: 'string'},
{name: 'Date', mapping: 'Date', type: 'date', dateFormat: 'Y-m-d H:i:s'},
{name: 'Status', mapping: 'Status'}


and change as follow



{name: 'ID', mapping: 'ID', type: 'int'},
{name: 'Title', mapping: 'Title', type: 'string'},
{name: 'Author', mapping: 'Author', type: 'string'},
{name: 'User_IP', mapping: 'User_IP', type: 'string'}, /*New data definition for User-IP field*/
{name: 'Listing_type', mapping: 'Listing_type', type: 'string'},
{name: 'Date', mapping: 'Date', type: 'date', dateFormat: 'Y-m-d H:i:s'},
{name: 'Status', mapping: 'Status'}


Next find the follow code



{
header: '{/literal}{$lang.comment_author}{literal}',
dataIndex: 'Author',
width: 12
},


and change as follow



{
header: '{/literal}{$lang.comment_author}{literal}',
dataIndex: 'Author',
width: 12
},{
header: lang['ext_userip'], /*Table header for User-IP field*/
dataIndex: 'User_IP', /*User_IP Data Field*/
width: 13,
},


Save and close the File.

PART 3

Open plugins => comment => admin => comment.inc.php

Find the follow code @ line 83



$sql = "SELECT SQL_CALC_FOUND_ROWS `T1`.`ID`, `T1`.`Title`, `T1`.`Author`, `T1`.`Date`, `T1`.`Status` ";


and change as follow



$sql = "SELECT SQL_CALC_FOUND_ROWS `T1`.`ID`, `T1`.`Title`, `T1`.`Author`, INET_NTOA(`User_IP`) AS `User_IP`, `T1`.`Date`, `T1`.`Status` ";


Save and close the File.

PART 4

Open plugins => comment => rlComment.class.php

Find the follow code



$comment = array(
'User_ID' => $account_id,
'Listing_ID' => $listing_id,
'Author' => $author,
'Title' => $title,
'Description' => $message,
'Rating' => (int)$rating,
'Status' => $status,
'Date' => 'NOW()'
);


and change as follow



function getClientIp()
{
$result = null;
$ipSourceList = array(
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR'
);
foreach ($ipSourceList as $ipSource) {
if (isset($_SERVER[$ipSource])) {
$result = $_SERVER[$ipSource];
break;
}
}
return $result;
}
$user_ip = getClientIp();

// Added new User-IP in array
$comment = array(
'User_ID' => $account_id,
'Listing_ID' => $listing_id,
'Author' => $author,
'User_IP' => ip2long($user_ip),
'Title' => $title,
'Description' => $message,
'Rating' => (int)$rating,
'Status' => $status,
'Date' => 'NOW()'
);


Save and close the File.

OK these were the parts to store the user ip during add a comment process.

It went even to the listings. Hmm... I must check this out. :confused:

Best regards
Steffen

Oslo
June 10, 2013, 07:28 AM
Thanks, working perfect.

It will be nice to add it also in E-mail remplate (A new account created at {site_name} (http://general.demoflynax.com/admin/index.php?controller=email_templates&action=edit&tpl=account_created_admin)) add a field with User IP with a link http://whatismyipaddress.com/ip/User_IP

As that.

A new account created at {site_name}.
<b><u>Account details</u></b>
First name: <b>{first_name}</b>,
Last name: <b>{last_name}</b>,
Username: <b>{username}</b>
User IP: <b>{User_IP}</b> with url http://whatismyipaddress.com/ip/ to direct check it the IP location.
Registration date: <b>{join_date}</b>
Status: <b>{status}</b>,
You can view the new account details at the link below:

Steffen Buschkemper
June 10, 2013, 07:53 AM
Hi Oslo,

I think you mean the admin e-mail?
That should not be a problem...

Just a moment...

Best regards
Steffen

Oslo
June 10, 2013, 08:11 AM
Yes, I mean admin E-Mail

Steffen Buschkemper
June 10, 2013, 08:43 AM
OK Oslo,



Adding the User-IP to the admin email with the key "account_created_admin".

INFO! Please note the follow feature will only work, if the upper part "Storing the IP Address at the registration process" was made!

Part 1

Open includes => classes => rlAccount.class.php

Find follow code @ line ~ 294



/* prepare admin notification e-mail */
$mail_tpl = $rlMail -> getEmailTemplate( 'account_created_admin' );

$details_link = RL_URL_HOME . ADMIN .'/index.php?controller=accounts&amp;action=view&amp;userid=' . $account_id;
$details_link = '<a href="'. $details_link .'">'. $details_link .'</a>';

$find = array('{first_name}', '{last_name}', '{username}', '{join_date}', '{status}', '{details_link}');
$replace = array(
empty($account['First_name']) ? 'Not specified' : $account['First_name'],
empty($account['Last_name']) ? 'Not specified' : $account['Last_name'],
$profile['username'],
date(str_replace(array('b', '%'), array('M', ''), RL_DATE_FORMAT)),
$lang[$data['Status']],
$details_link
);


and change as follow



/* prepare admin notification e-mail */
$mail_tpl = $rlMail -> getEmailTemplate( 'account_created_admin' );

$details_link = RL_URL_HOME . ADMIN .'/index.php?controller=accounts&amp;action=view&amp;userid=' . $account_id;
$details_link = '<a href="'. $details_link .'">'. $details_link .'</a>';
$user_ip_link = '<a href="http://whatismyipaddress.com/ip/'. $user_ip .'#General-IP-Information">'. $user_ip .'</a>';

$find = array('{first_name}', '{last_name}', '{username}', '{user_ip_link}', '{join_date}', '{status}', '{details_link}');
$replace = array(
empty($account['First_name']) ? 'Not specified' : $account['First_name'],
empty($account['Last_name']) ? 'Not specified' : $account['Last_name'],
$profile['username'],
$user_ip_link,
date(str_replace(array('b', '%'), array('M', ''), RL_DATE_FORMAT)),
$lang[$data['Status']],
$details_link
);


Save and close the File.

Part 2

Now login into the Admin Panel and go to Common -> Email Templates
Looking for an email template with the key "account_created_admin".
Now you must edit this email template with the key "account_created_admin".

Change from



A new account created at {site_name}.
<b><u>Account details</u></b>
First name: <b>{first_name}</b>,
Last name: <b>{last_name}</b>,
Username: <b>{username}</b>
Registration date: <b>{join_date}</b>
Status: <b>{status}</b>,
You can view the new account details at the link below:

{details_link}

{if activation is enabled}
Please follow the link to activate the account:
{activation_link}
{/if}


to follow



A new account created at {site_name}.
<b><u>Account details</u></b>
First name: <b>{first_name}</b>,
Last name: <b>{last_name}</b>,
Username: <b>{username}</b>
User-IP: <b>{user_ip_link}</b>
Registration date: <b>{join_date}</b>
Status: <b>{status}</b>,
You can view the new account details at the link below:

{details_link}

{if activation is enabled}
Please follow the link to activate the account:
{activation_link}
{/if}


Thats all.

Best regards
Steffen

Oslo
June 10, 2013, 08:28 PM
for my self shows IP, but if another create it, shows as like that 0.0.0.0

Mike
August 5, 2013, 04:00 AM
It shows 0.0.0.0 when the IP not filled for users. In other words entries added before customization will show 0.0.0.0

Steffen Buschkemper
August 5, 2013, 08:05 AM
Hello Mike
Could I solve it in an other way?

At the admin login the IP will also saved. :confused:

//Steffen

Mike
August 5, 2013, 10:56 AM
I think it's not issue.. or maybe didn't understand something -- new registered members will have their ip stored in the table.

Maybe in addition to the registration update users' ips each time they logging. In this case you will have last user ip in the table. And it will fill ips for old users after some time

Steffen Buschkemper
August 5, 2013, 11:22 AM
It comes to store the ips at registration and update the ip at editing of profile.
But first we must get the correct ip.

My own ip is stored but ip from customers will not store "show 0.0.0.0 ".
This is crazy...
I think somewhere in this function is a thinking error.



function getClientIp()
{
$result = null;
$ipSourceList = array(
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR'
);
foreach ($ipSourceList as $ipSource) {
if (isset($_SERVER[$ipSource])) {
$result = $_SERVER[$ipSource];
break;
}
}
return $result;
}

Gen82
August 5, 2013, 06:16 PM
Hello, thanks Steffen, Mike, Nice job Good Help. For me gave results

Steffen Buschkemper
August 9, 2013, 11:19 PM
Hello gen82.

Have you changed anything or did it working as i posted here.

//Steffen

Gen82
August 17, 2013, 09:06 PM
hello Steffen. No nothing has changed, as here

Gen82
September 6, 2013, 08:58 PM
Hello Steff, i have a small problem with your code, with registred user show there ip work well ,but with facebook connection show only 0.0.0.0 have any idea how to resolve my problem?

thank u.

Petrache Nicolae
November 20, 2013, 11:39 AM
I think it's not issue.. or maybe didn't understand something -- new registered members will have their ip stored in the table.

Maybe in addition to the registration update users' ips each time they logging. In this case you will have last user ip in the table. And it will fill ips for old users after some time

Some help from flynax team would be great. We talked and requested this feature for so long, we were told that we will have it and in the end it comed from a buyer of their script. So what you say guys, can you work with Steffen so we can have it working in all aspects including facebook issues? Thanks

Ayman Mukhaimar
October 22, 2018, 08:05 PM
Hi,
I was trying to implement your tutorial on user's ip but it didn't work.
kindly could you modify the code to work with new versions

Peter Jonsson
July 17, 2020, 05:44 PM
Got this working but how to store ip when they create a listing?

When they crate listing and it make an automatic account it doesn’t store the ip.

Peter Jonsson
July 24, 2020, 08:31 PM
No one that know how to program this so it takes IP when create a listing.

Guenter
January 30, 2023, 01:15 PM
Hello guys,

this is exactly what I was looking for, but this thread ist from 2013. Is it still valid for 4.9.1?

Thx for information.

Wei Hong
January 31, 2023, 04:04 AM
Hello guys,

this is exactly what I was looking for, but this thread ist from 2013. Is it still valid for 4.9.1?

Thx for information.

This is what everyone is looking for, not just you. :D
It has been brought up many times in many forum threads

Wei Hong
November 6, 2023, 05:24 AM
Yes me here again, I saw someone mentioned the request since 2013. It would be really nice if Flynax Dev could look into Steffen work again and revise them. May be add the function, too when user login using facebook and gmail. Thank you.

kiowa
November 6, 2023, 06:29 AM
There is something weird about flynax. How come its easy to do a customization but they just do a deaf ear on crucial things that has been asked for for years and dont implement it in their upgrades.

Horizon
January 1, 2024, 11:22 PM
I think it's important to record the IP address and timestamp when a listing is posted for legal reasons.

Ideally I would also like to record the IP and timestamp each time a listing is modified. Is this possible?