Help - Search - Members - Calendar
Full Version: Echoing Username
Invision Power Services > Community Forums > Community Web Design and Coding
cjpadlock
Hey, I was just wondering if anyone knew how to echo the name of a logged in user in any page on the server.

Like say I had my IPFM or IPB in domain.com/invision and I wanted to display the name off the logged in person at domain.com/index.php

is that possible? with cookies or somthing?
.Logan
Yes, you'd need to write a script to read the user's cookie, grab the member_id, then connect to the IPB database and get the user's display name from that row.
UBERHOST.NET
Well, yeah with cookies most certainly. You could also pass it as a variable in the URL.
Michael P
I use this:

CODE


// you need to set $cookie_pfx to the cookie prefix original.gif

$uid = $_COOKIE[$cookie_pfx . "member_id"];

// Get the username from the id - set $prefix as the prefix without the _

$jsql = "SELECT " . $prefix . "_members.mgroup, " . $prefix . "_members.name, " . $prefix . "_members.member_login_key, ". $prefix . "_members_converge.converge_pass_hash, " . $prefix . "_members_converge.converge_pass_salt
FROM " . $prefix . "_members
LEFT OUTER JOIN " . $prefix . "_members_converge ON " . $prefix . "_members.id = " . $prefix . "_members_converge.converge_id
WHERE id = '$uid'";
$result = mysql_query($jsql) or die ($jsq);
$row = mysql_fetch_array($result);

// (I used it for more than username - thus why its a big query)

$username = $row['name'];

echo ($username);

cjpadlock
That sounds right, does anyone know how to do it for Invision File Manager?
.Logan
Michael,
Your's is an awful lot of work. Mine works perfectly and only consists of this:
CODE
$pre = ""; //cookie prefix if one exists
$mid = intval($_COOKIE[$pre.'member_id']);
if ($mid > 0)
{
    $row = mysql_fetch_array(mysql_query('SELECT members_display_name FROM ibf_members WHERE id='.$mid));
}

print ($mid > 0 && $row[0]) ? "".$row[0] : "Unable to retrieve username. You're either not logged in or not registered";
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.