MyBB Community Forums

Full Version: Getting the user's last post IP...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is it possible to get a user's last post IP via code?
You've made similar thread before: http://community.mybb.com/thread-84074.html

If you want to get the User's IP in post then you can use this variable;
$post['ipaddress']
(2011-05-10, 03:24 AM)Yaldaram Wrote: [ -> ]You've made similar thread before: http://community.mybb.com/thread-84074.html

If you want to get the User's IP in post then you can use this variable;
$post['ipaddress']
How exactly does the variable contain a certain users last IP?
Currently, my script only gets the user's last login IP by running a query...
Where exactly you want to show the User's IP ? In post or any where else ?
You can get the IP address from where a user has last posted with this code:
$query = $db->query("SELECT ipaddress FROM mybb_posts WHERE uid=1 ORDER BY dateline DESC LIMIT 1");
$lastpostip = $db->fetch_field($query, "ipaddress");
Of course you need to change the uid (now = 1) in the query to make it more dynamic. But you already have the users last ip, so I guess you know how to do that.
This is what my script currently does:
1. Get the Users current IP. $_SERVER['REMOTE_ADDR'];
2. Run a DB Query getting a user's info.
$query = $db->query("SELECT username,postnum,usergroup,additionalgroups,lastip FROM mybb_users WHERE lastip='$ip'");
3. echo the info.
Currently, step 2 gets the users information based on their last login IP, I want it to get the information based on their last post IP. That way, the script only gets the information of active posting uesrs.
Then try this:
$query = $db->query("SELECT u.username, u.postnum, u.usergroup, u.additionalgroups, p.ipaddress FROM ".TABLE_PREFIX."posts p INNER JOIN ".TABLE_PREFIX."users u ON p.uid = u.uid WHERE p.ipaddress='$ip' ORDER BY p.dateline DESC LIMIT 1");

Edit: replaced php with code tags to prevent the content from being stretched.