MyBB Community Forums

Full Version: Useragent in Who's Online?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there any ability to show the useragent of a visitor in the who's online section? I see the coding there and have already changed it a bit to show like this:



Quote:<br /><span class="smalltext">{$lang->ip} {$user['ip']} <a href="modcp.php?action=ipsearch&amp;ipaddress={$user['ip']}&amp;search_users=1">{$lang->lookup}</a> | <a href="http://network-tools.com/default.asp?prog=express&host={$user['ip']}">[Network Tools Lookup]</a></span>

I just added another link so I could do a more extensive lookup on IP addresses. I would also like to display the useragent there. I went into the database and found the table called "sessions". It has a column for IP, I looked over and saw one or useragent. I tried putting the code like this:

Quote:<br /><span class="smalltext">{$lang->ip} {$user['ip']} {$user['useragent']} <a href="modcp.php?action=ipsearch&amp;ipaddress={$user['ip']}&amp;search_users=1">{$lang->lookup}</a> | <a href="http://network-tools.com/default.asp?prog=express&host={$user['ip']}">[Network Tools Lookup]</a></span>


But that wouldn't work, it doesn't display the visitor's useragent. Is there any way to do this straight from who's online WITHOUT a plugin?


-ZuFu

You would need to retrieve the useragent from the active session. (mybb_sessions)
Malcolm Wrote:You would need to retrieve the useragent from the active session. (mybb_sessions)

I know, that's what I said in the OP. If you notice, the ip is called upon the same way I'm trying to call the useragent. {$user['ip']} is a column in mybb_sessions, as is {$user['useragent']} also a column in mybb_sessions. But for some reason I'm not getting anything when I make my code like the one below. I don't know why, so I suppose I'm calling it wrong. I tried doing

{$lang->useragent} {$user['useragent']}

but that didnt' work either. Then I tried creating a whole new span to do it and it didn't work either:

<span class="smalltext">{$lang->useragent} {$user['useragent']}</span>

So, I'm at a loss now, no clue what to do or how to call this out.


(04-17-2011, 03:31 AM)MasterZuFu Wrote: [ -> ]I went into the database and found the table called "sessions". It has a column for IP, I looked over and saw one or useragent. I tried putting the code like this:

Quote:<br /><span class="smalltext">{$lang->ip} {$user['ip']} {$user['useragent']} <a href="modcp.php?action=ipsearch&amp;ipaddress={$user['ip']}&amp;search_users=1">{$lang->lookup}</a> | <a href="http://network-tools.com/default.asp?prog=express&host={$user['ip']}">[Network Tools Lookup]</a></span>
Open ./inc/functions_online.php page and find;
function build_wol_row($user)
{
	global $mybb, $lang, $templates, $theme, $session;

and Change it to;
function build_wol_row($user)
{
	global $mybb, $db, $lang, $templates, $theme, $session;

Now within the same file, find;
			$online_name = build_profile_link($user['username'], $user['uid']).$invisible_mark;
And add the following code just after that;
			$query = $db->simple_select("sessions", "useragent", "uid='{$user['uid']}'");
			$user['useragent'] = $db->fetch_field($query, "useragent");

Save the file.

Now Go to: ACP > Templates > Your theme's templates > Online Templates > online_row > and find;
{$online_name}
And add the following code just after that;
<span style="float: right; font-size: 9px;">Useragent: {$user['useragent']}</span>

Save template.

It should result into this;
[Image: attachment.php?aid=416]
That's not working for me.

[attachment=22335]


I had to change the code as well, just a little bit, I had to add the following:

Quote:<tr>
<td class="trow1">{$online_name}<br/><span style="float: left; font-size: 9px;">Useragent: {$user['useragent']}</span> {$user_ip}</td>
<td align="center" class="trow2">{$online_time}</td>
<td class="trow1" width="50%">{$location}</td>
</tr>

Ah, ok, i figured out what I did wrong. I put that code UNDER it, not over it. ok. it works now...but..

it shows the same UA for all guests and bots.
It works (for bots and guests, too) if one uses
"sid='{$user['sid']}'"
instead of
"uid='{$user['uid']}'"
Please look at the last post date before replying. This thread hasn't had a new reply in over 3 years.