MyBB Community Forums

Full Version: fetch Reg IP and Last IP from Users in moderation.php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Ok, here's the deal.

First I added 2 extra fields to the member_profile_modoptions template:

Registration IP
Last Known IP

I used {$memprofile['regip']} and {$memprofile['lastip']} to get that.

Then I thought... why not cross checking IPs on the fly like we used to do in that other... (nevermind). So I added 2 pairs more of templates and one variable for each new case in moderation.php (getregip and getlastip).

Problem is {$memprofile['regip']} and {$memprofile['lastip']} return nothing at this point, while {$mybb->users[etc]} works... but logically always returns my own data for every user.
Hmm, weird, that should have fetched it.

You might have to write a simple query if it doesn't work, something like:

$uid = intval($mybb->input['uid']);
$user = get_user($uid);
$user_reg_ip = $user['regip']
//Further some modification or code

Likewise, you could do for last IP as well and then output it using member profile hooks.
I'll try that. Thanks! This has everything to become my crash course into php Smile
Are you sure {$memprofile['regip']} doesn't work? I just tried on my localhot with no core modifications and the following member_profile_modoptions template:

<br /><table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" width="100%" class="tborder">
<tr>
<td colspan="2" class="thead"><strong>{$lang->mod_options}</strong></td>
</tr>
<tr>
<td class="trow1">
<ul>
<li><a href="{$mybb->settings['bburl']}/modcp.php?action=editprofile&amp;uid={$uid}">{$lang->edit_in_mcp}</a></li>
<li><a href="{$mybb->settings['bburl']}/modcp.php?action=banuser&amp;uid={$uid}">{$lang->ban_in_mcp}</a></li>
</ul>
</td>
</tr>
<tr>
<td class="trow2">
Register IP: {$memprofile['regip']}<br />
Last IP: {$memprofile['lastip']}<br />
{$memprofile['usernotes']}<br />
<a href="{$mybb->settings['bburl']}/modcp.php?action=editprofile&amp;uid={$uid}">{$lang->edit_usernotes}</a>
</td>
</tr>
</table>

And here was the output:

[Image: 2mo9lpl.png]
That works ok!

But I went a little further:

I hrefd those in links with templates that should make these work:
<br /><table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" width="100%" class="tborder">

<tr>
  <td colspan="2" class="thead"><strong>{$lang->mod_options}</strong></td>
</tr>
<tr>
  <td class="trow1">
    <ul>
      <li><a href="moderation.php?action=getregip&amp;uid={$uid}"><strong>Registration IP :</strong> {$memprofile['regip']}</a></li>
      <li><a href="moderation.php?action=getlastip&amp;uid={$uid}"><strong>Last Known IP :</strong> {$memprofile['lastip']}</a></li>
      <li><a href="{$mybb->settings['bburl']}/modcp.php?action=editprofile&amp;uid={$uid}">{$lang->edit_in_mcp}</a></li>
      <li><a href="{$mybb->settings['bburl']}/modcp.php?action=banuser&amp;uid={$uid}">{$lang->ban_in_mcp}</a></li>
    </ul>
  </td>
</tr>
<tr>
  <td class="trow2">
    {$memprofile['usernotes']}<br />
    <a href="{$mybb->settings['bburl']}/modcp.php?action=editprofile&amp;uid={$uid}">{$lang->edit_usernotes}</a>
  </td>
</tr>


in moderation.php

So, to the existent

	// Lets look up the ip address of a post
	case "getip":
		add_breadcrumb($lang->nav_getip);
		if(!is_moderator($fid, "canviewips"))
		{
			error_no_permission();
		}

		$hostname = @gethostbyaddr($post['ipaddress']);
		if(!$hostname || $hostname == $post['ipaddress'])
		{
			$hostname = $lang->resolve_fail;
		}

		$username = build_profile_link($post['username'], $post['uid']);

		// Moderator options
		$modoptions = "";
		if($mybb->usergroup['canmodcp'] == 1)
		{
			eval("\$modoptions = \"".$templates->get("moderation_getip_modoptions")."\";");		
		}

		eval("\$getip = \"".$templates->get("moderation_getip")."\";");
		output_page($getip);
		break;

I added this for Registration IP

	// Lets look up the regip address of a user
	case "getregip":
		add_breadcrumb($lang->nav_getip);

		$hostname = @gethostbyaddr($memprofile['regip']);
		if(!$hostname || $hostname == $memprofile['regip'])
		{
			$hostname = $lang->resolve_fail;
		}

		$username = build_profile_link($memprofile['regip'], $memprofile['uid']);

		// Moderator options
		$modipregoptions = "";
		if($mybb->usergroup['canmodcp'] == 1)
		{
			eval("\$modipregoptions = \"".$templates->get("member_profile_modoptions_getip_reg_options")."\";");
		}

		eval("\$getregip = \"".$templates->get("member_profile_modoptions_getip_reg")."\";");
		output_page($getregip);
		break;

and this for Last Known IP

	// Lets look up the lastip address of a user
	case "getlastip":
		add_breadcrumb($lang->nav_getip);

		$hostname = @gethostbyaddr($memprofile['lastip']);
		if(!$hostname || $hostname == $memprofile['lastip'])
		{
			$hostname = $lang->resolve_fail;
		}

		$username = build_profile_link($memprofile['username'], $memprofile['uid']);

		// Moderator options
		$modiplastoptions = "";
		if($mybb->usergroup['canmodcp'] == 1)
		{
			eval("\$modiplastoptions = \"".$templates->get("member_profile_modoptions_getip_last_options")."\";");
		}

		eval("\$getlastip = \"".$templates->get("member_profile_modoptions_getip_last")."\";");
		output_page($getlastip);
		break;		

Of course there exist now 4 more new templates making the liaisons:

member_profile_modoptions_getip_last
member_profile_modoptions_getip_last_options
member_profile_modoptions_getip_reg
member_profile_modoptions_getip_reg_options

Shall I add these to this post? Smile
You could do so that people wishing to do the same in the future can do so.


The new four templates:



Templates to build Registration IP data in the getregip PHP case.

member_profile_modoptions_getip_reg

<html>
<head>
<title>{$mybb->settings['bbname']} - Get User Registration IP Address</title>
{$headerinclude}
</head>
<body>
{$header}
  <table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
    <tr>
      <td class="thead" colspan="2"><strong>Get User Registration IP Address</strong></td>
    </tr>
    <tr>
      <td class="trow1" width="20%"><strong>{$lang->username}</strong></td>
      <td class="trow1">{$username}</td>
    </tr>
    <tr>
      <td class="trow2"><strong>{$lang->ip_address}</strong></td>
      <td class="trow2">{$memprofile['regip']}</td>
    </tr>
    <tr>
      <td class="trow1"><strong>{$lang->hostname}<br /><span class="smalltext">{$lang->if_resolvable}</span></strong></td>
      <td class="trow2">{$hostname}</td>
    </tr>
{$modiplastoptions}
</table>
{$footer}
</body>
</html>

member_profile_modoptions_getip_reg_options

<tr>
<td class="trow2"><strong>{$lang->mod_options}</strong></td>
<td class="trow2">
	<a href="modcp.php?action=ipsearch&amp;ipaddress={$memprofile['regip']}&amp;search_users=1">{$lang->search_ip_users}</a><br />
	<a href="modcp.php?action=ipsearch&amp;ipaddress={$memprofile['regip']}&amp;search_posts=1">{$lang->search_ip_posts}</a><br />
	<a href="modcp.php?action=iplookup&ipaddress={$memprofile['regip']}" onclick="MyBB.popupWindow('{$mybb->settings['bburl']}/modcp.php?action=iplookup&ipaddress={$memprofile['regip']}', 'iplookup', 500, 250); return false;">{$lang->info_on_ip}</a>
</td>
</tr>



Templates to build Last Known IP data in the getlastip PHP case.

member_profile_modoptions_getip_last

<html>
<head>
<title>{$mybb->settings['bbname']} - Get User Last Known IP Address</title>
{$headerinclude}
</head>
<body>
{$header}
  <table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
    <tr>
      <td class="thead" colspan="2"><strong>Get User Last Known IP Address</strong></td>
    </tr>
    <tr>
      <td class="trow1" width="20%"><strong>{$lang->username}</strong></td>
      <td class="trow1">{$username}</td>
    </tr>
    <tr>
      <td class="trow2"><strong>{$lang->ip_address}</strong></td>
      <td class="trow2">{$memprofile['lastip']}</td>
    </tr>
    <tr>
      <td class="trow1"><strong>{$lang->hostname}<br /><span class="smalltext">{$lang->if_resolvable}</span></strong></td>
      <td class="trow2">{$hostname}</td>
    </tr>
{$modiplastoptions}
</table>
{$footer}
</body>
</html>

member_profile_modoptions_getip_last_options

<tr>
<td class="trow2"><strong>{$lang->mod_options}</strong></td>
<td class="trow2">
	<a href="modcp.php?action=ipsearch&amp;ipaddress={$memprofile['lastip']}&amp;search_users=1">{$lang->search_ip_users}</a><br />
	<a href="modcp.php?action=ipsearch&amp;ipaddress={$memprofile['lastip']}&amp;search_posts=1">{$lang->search_ip_posts}</a><br />
	<a href="modcp.php?action=iplookup&ipaddress={$memprofile['lastip']}" onclick="MyBB.popupWindow('{$mybb->settings['bburl']}/modcp.php?action=iplookup&ipaddress={$memprofile['lastip']}', 'iplookup', 500, 250); return false;">{$lang->info_on_ip}</a>
</td>
</tr>
If anyone has any idea how to make this work. My experience is not enough to understand what member Crazy4cs kindly suggested, whilst I believe many will feel the same.

The templates are ready, we only need to make the variables work and we'll have a swift IP tracking tool.
Didn't this worked for you? I thought as euantor suggested you solved problems displaying IP in profile.
Euantor suggestion works well, but when I click the IPs and leave into the new PHP cases, the {$memprofile['xxx']} returns no more data and everything appears empty and returns ths user as "guest".

Where and how do I insert the variables you suggested in post #2? it smells they will work, but I would need to understand what they do and how to use that.
Pages: 1 2 3