1
talunceford
Storing a registerd users last known IP Addy. Any Ideas?

Ok, as you might have guessed by the title, I need to log the IP address of the users that have actual accounts with my bf2online.com site. I need it to log the IP address each time they login. I use this ip address to display a user specific national flag beside thier name. Any ideas on how to do this? I've got some code implemented right now, but I don't think that its working the way that I want it to. I don't think that its updating the xoops_users table. Any and all help is very much appreciated.

2
Mithrandir
Re: Storing a registerd users last known IP Addy. Any Ideas?

I know how I would do it with XOOPS 2.2:

1) Make a new module with a dynamic field called "user_ip" or something
2) Put a block in that module with this code:
global $xoopsUser;
if (
$xoopsUser) {
    
$ip xoops_getenv('REMOTE_ADDR');
    if (
$ip != $xoopsUser->getVar('user_ip') ) {
        
$xoopsUser->setVar('user_ip'$ip);
        
$member_handler =& xoops_gethandler('member');
        
$member_handler->insertUser($xoopsUsertrue);
    }
}

3
talunceford
Re: Storing a registerd users last known IP Addy. Any Ideas?

Thanks Mith, I'll try that!

4
Mithrandir
Re: Storing a registerd users last known IP Addy. Any Ideas?

Actually... you don't need the module part.

Just XOOPS 2.2 (naturally, you can only test with 2.1 until 2.2 is out)

1) A custom field of type "textfield" and name "user_ip"
- Set the field to be editable by noone
- Set the field to be visible by noone (unless you want e.g. the webmasters to be able to see this on the user's profile...)

2) A custom block, visible on all pages, PHP type, with the above-mentioned code.

5
javier
Re: Storing a registerd users last known IP Addy. Any Ideas?
  • 2005/6/17 17:22

  • javier

  • Not too shy to talk

  • Posts: 184

  • Since: 2002/8/6 1


Excuse me if i understand wrong, but exist a XOOPS module & block,

It show the users online and his country flag at side, see yourself inhttp://www.xoopsmalaysia.org (see in the left menu bar)

Download inhttp://www.xoopsmalaysia.org/modules/wfdownloads/singlefile.php?cid=2&lid=65

I think maybe you can take a look to these module code too, excuse my bad english, is not my natural language.

best regards
Javier

6
talunceford
Re: Storing a registerd users last known IP Addy. Any Ideas?

LOL, Yeah, thats where I got the code from. I am using it to write smarty variables for my theme.

7
talunceford
Re: Storing a registerd users last known IP Addy. Figured it out, code available

I figured out a way that stores the users ip address when they visit the site.

Using this sql, create a field in the xoops_users table with this criteria.

`last_known_ip` varchar(100) NOT NULL default '',

Ok, now edit the checklogin.php file in the include directory and add these lines to it. Make sure that you find the lines called out below.

// RMV-NOTIFY
    // Perform some maintenance of notification records
    
$notification_handler =& xoops_gethandler('notification');
    
$notification_handler->doLoginMaintenance($user->getVar('uid'));
    
    
//////////  BEGIN LOGGING OF USER IP
         
$lognom $user->getVar('uname');
         
$addip getenv("REMOTE_ADDR");
    
mysql_query("UPDATE ".$xoopsDB->prefix("users")." SET last_known_ip='$addip' WHERE uname='$lognom'");
    
//////// END LOGGING OF USER IP
    
    
redirect_header($url1sprintf(_US_LOGGINGU$user->getVar('uname')));
    
} else {

    
redirect_header(XOOPS_URL.'/user.php',1,_US_INCORRECTLOGIN);
}
exit();
?>


This code is almost at the bottom of the file. Just add the lines noted above right after the $notification_handler call.

Now what this does is every time that a user logs into the site, it updates his/her information with the ip address of where they were accessing your site from. Granted this information is only valuable if you use it, but being that I need the ip address to associate it with a country flag, it is very much necessary for bf2online.com.


Enjoy!
Tim
www.tswn.com | www.bf2online.com | aquaria.tswn.com | www.bf2142online.org

8
talunceford
Re: Storing a registerd users last known IP Addy. Any Ideas?

Quote:

Mithrandir wrote:
I know how I would do it with XOOPS 2.2:

1) Make a new module with a dynamic field called "user_ip" or something
2) Put a block in that module with this code:
global $xoopsUser;
if (
$xoopsUser) {
    
$ip xoops_getenv('REMOTE_ADDR');
    if (
$ip != $xoopsUser->getVar('user_ip') ) {
        
$xoopsUser->setVar('user_ip'$ip);
        
$member_handler =& xoops_gethandler('member');
        
$member_handler->insertUser($xoopsUsertrue);
    }
}


Hey Mithy, what would be cool is if the next version allowed you to choose whether or not the site owner displayed the users nationality flag, granted if the user wanted to that is. Have and option that the user could choose when registering or updating his/her profile.

Just an idea.....
Tim
www.tswn.com | www.bf2online.com | aquaria.tswn.com | www.bf2142online.org

9
Mithrandir
Re: Storing a registerd users last known IP Addy. Any Ideas?

Another dynamic field with type yesno - for example "show_flag".

Then in the block code:
global $xoopsUser;
if (
$xoopsUser) {
    
$ip xoops_getenv('REMOTE_ADDR');
    if (
$ip != $xoopsUser->getVar('user_ip') ) {
        
$xoopsUser->setVar('user_ip'$ip);
        
$member_handler =& xoops_gethandler('member');
        
$member_handler->insertUser($xoopsUsertrue);
    }
    if (
$xoopsUser->getVar('show_flag') == 1) {
        
//user wants flag shown, deal with it
    
}
}
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

10
talunceford
Re: Storing a registerd users last known IP Addy. Any Ideas?

Yep, I think that would be "KICK A$$" to quote cartman....
Tim
www.tswn.com | www.bf2online.com | aquaria.tswn.com | www.bf2142online.org

Login

Who's Online

247 user(s) are online (150 user(s) are browsing Support Forums)


Members: 0


Guests: 247


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits