MyBB Community Forums

Full Version: problem with a plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello,

I have installed  this plugin on a testforum first thing i noticed is that it is not recording ip addresses i fixed that but it is not recording guests and i don't understand why i mean
if(!$mybb->user['uid'])
{
      //not logged in
}

should do the trick but it's not ....
(2021-03-10, 07:27 PM)Erikbe Wrote: [ -> ]Hello,

I have installed  this plugin on a testforum first thing i noticed is that it is not recording ip addresses i fixed that but it is not recording guests and i don't understand why i mean
if(!$mybb->user['uid'])
{
      //not logged in
}

should do the trick but it's not ....


A guest will have a user id of 0

and you are saying

!$mybb->user['uid']

and then saying:

Quote:should do the trick but it's not ....

but, did you forget that there is still a guest uid = 0???

so, I am thinking there is your issue as 0 is still equal to a uid & not not equal to? Or am I just not thinking right & half asleep thinking on this?

thinking  still on that, perhaps we must remember:

[ 0 ] _ Guests uid
[ xxx ] _ Registered uid
thus all such has a uid and is not empty thus can be equaled to as even if a guest for example is not logged in it is still going to be found as its respective uid... of '0' but alas as I am just waking up for the day pondering this over a first coffee, dunno as my suggestion could be off based to your needs...

so perhaps?
        if ($mybb->user['uid'] == 0)
        {
            // is guest then, blah
        }


umm, I don't know anything about this particular plugin nor have I yet to try it and I am just getting the first coffee and puff of the day in but simply was curious if say have you also simply tried rather than ! if not via uid if  uid == 0,  or even say as an alternative instead defining guest if gid is equal to guest gid then:


        if ($mybb->user['usergroup'] == 1)
        {
            // is guest then, blah
        }


we must remember:

[ 1 ] _ Guests
[ 2 ] _ Registered
[ 3 ] _ Super Moderators
[ 4 ] _ Administrators
[ 5 ] _ Awaiting Activation
[ 6 ] _ Moderators
[ 7 ] _ Banned

thus all such has a gid and is not empty thus can be equaled to as even if a guest for example is not logged in it is still going to be found as its respective gid... but alas as I am just waking up for the day pondering this over a first coffee, dunno as my suggestion could be off based to your needs...
Hello,

hmmm the person with uid = 1 is the person who installed the forum and most likely the super admin to (allthough this can be changed in /inc/config.php) it is impossible this is a guest .... gid 1 is the usergroup for guests but that's not the same.

when you post on a mybb as a guest and look at the database with a tool like phpMyAdmin mybb assigns uid = 0 to guests and username field is empty

i fail to see why the code fails !$mybb->user['uid'] bit obviously there must be a reason .Not asking anybody to finisch my homework here i'll look for the reason(s) why it is not working.
!$mybb->user['uid']
 * again ! is perhaps your issue

again suggested perhaps because it appears you are expecting by comparison an empty value rather than defining to find if uid '0' then

and I did mention that wanting to by comparison return uid = none rather than returning uid = 0 as the possible source of your issue already

and the suggestion of == 1 was for the alternate suggestion for by gid as guest gid = 1 , not uid  as guest uid = 0 though you may have read it while I was editing and writing the rest an not noticed the two diff suggestional routes...
it is getting late in here tomorrow is another day  thank you for reading and trying to offer me advice now get your coffee Big Grin
(2021-03-10, 10:05 PM)Erikbe Wrote: [ -> ]it is getting late in here tomorrow is another day  thank you for reading and trying to offer me advice now get your coffee Big Grin


haha, right?!! I think there might be more to your issue though and I am admittedly not knowledgeable about how exactly guest ips are stored but aren't they gathered differently? and if so that may be something to ponder on as while I still havent looked at the specific plugin you are speaking of except by viewings screens I would assume that it requires say username, userid,  page viewed,  useragent, ip, date and I am honestly not sure if all of those are recorded for guest ips in post iplogged, whosonline or sessions or not thus hopefully someone with admittedly more knowledge on how guest ips are handled will be able to help ya more hopefully and my apologies for my admitted lacking knowledge on overall guest ip handling.



anyhoo, one completely unrelated issue i did note and figured I would helpfully mention in case you had not yet noticed that on a quick glance of first installing plugin just now and something that annoyed me before looking any further was while the registered uid ip history was displayed and that was nice to see as I thought I read that you said it wasn't displaying?

for defined:

if ($user !== 0)

my first glance notice was that while uid ip history was output correctly, said related links for username, userid & page where not correct when output in:

forum/admin/modules/tools/ip_history_logs.php

	// Output Every row from DB
while($section = $db->fetch_array($query))
	{
	    $username = htmlspecialchars_uni($section['username']);
		$table->construct_cell("<a target='_blank' href=\"/member.php?action=profile&uid={$section['uid']}\">$username</a>", array("class" => "align_center", "width" => '60'));
		$table->construct_cell("<a target='_blank' href=\"/member.php?action=profile&uid={$section['uid']}\">{$section['uid']}</a>", array("class" => "align_center", "width" => '60'));
		$table->construct_cell("<strong><a href=\"/{$section['page']}\">{$section['page']}</a></strong>");
		$table->construct_cell(htmlspecialchars_uni($section['useragent']));
		$table->construct_cell(HandleIP($section['ip']), array("class" => "align_center", "width" => '90'));
		$table->construct_cell(my_date('relative',$section['createdate'], '', 2), array("class" => "align_center", "width" => '90'));
		$table->construct_row();
	}

thus simply adding

{$mybb->settings['bburl']}

sorted that out for me as far as now displaying related linkage correctly:

	// Output Every row from DB
while($section = $db->fetch_array($query))
	{
	    $username = htmlspecialchars_uni($section['username']);
		$table->construct_cell("<a target='_blank' href=\"{$mybb->settings['bburl']}/member.php?action=profile&uid={$section['uid']}\">$username</a>", array("class" => "align_center", "width" => '60'));
		$table->construct_cell("<a target='_blank' href=\"{$mybb->settings['bburl']}/member.php?action=profile&uid={$section['uid']}\">{$section['uid']}</a>", array("class" => "align_center", "width" => '60'));
		$table->construct_cell("<strong><a href=\"{$mybb->settings['bburl']}/{$section['page']}\">{$section['page']}</a></strong>");
		$table->construct_cell(htmlspecialchars_uni($section['useragent']));
		$table->construct_cell(HandleIP($section['ip']), array("class" => "align_center", "width" => '90'));
		$table->construct_cell(my_date('relative',$section['createdate'], '', 2), array("class" => "align_center", "width" => '90'));
		$table->construct_row();
	}
Hello,

The SQL query used to retrieve the data in /admin/modules/tools/ip_history_logs is an issue i see there are entries in the ip_history table -but it isn't displayed this query

$db->query("SELECT u.username, ip.uid, ip.ip, ip.page, ip.useragent, ip.createdate FROM . " TABLE_PREFIX . "ip_history ip
INNER JOIN . "TABLE_PREFIX . "users u ON (ip.uid = u.uid) {$where} ORDER BY {$sortby} {$order} LIMIT {$limit}");

mybb sets uid to 0 for guests but leaves username empty so this query is failing unless you are logged in.

about the incorrect links yes i did notice that to.
There is no user with uid 0, so you have two ways:
1. create a separate query for guests
2. add an union:
`SELECT u.username, ip.uid, ip.ip, ip.page, ip.useragent, ip.createdate FROM " . TABLE_PREFIX . "ip_history ip
INNER JOIN . "TABLE_PREFIX . "users u ON (ip.uid = u.uid) {$where}
UNION 'guest', 0, ip.ip, ip.page, ip.useragent, ip.createdate FROM " . TABLE_PREFIX . "ip_history ip {$where}
ORDER BY {$sortby} {$order} LIMIT {$limit}`

Note that if your where reffers to the users table, you'll have to create a second $where.
Hello,

In inc/functions.php there is a function get_user() that takes an uid as an argumennt so since uid == 0 does not exist i could use that to get the username
if($mybb->user['uid'] > 0)
{
get_user($mybb->user['uid']);
}

hmmm gotta check whether $mybb->user['uid'] is not empty otherwise it won't work.

thanks Crazycat i'll try that query got it to display correctly no links in the output table when uid is 0.

Hello,

it seems when uid is greater then 0 you can use $mybb->user['username'] also restored datatables but it strikes through the tab text and when there is no data in the log yet there is this big ugly gap i don't know what is causing this issue never used datatables before but it seems nice no need for draw_admin_pagination();
As guests are all users who have not an account you need to add some reference for every possible guest account and sepparate by a query as crazycat sugest you.

But take that piece of code added and use a userkey if guest to verify possible different accounts and record those entries in a new table that should do the trick and must work.
Pages: 1 2