Show login username

Discuss features as they are added to the new version. Give us your feedback. Don't post bug reports, feature requests, support questions or suggestions here.
Forum rules
Discuss features as they are added to the new version. Give us your feedback. Don't post bug reports, feature requests, support questions or suggestions here. Feature requests are closed.
Post Reply
Black-Chaos
Registered User
Posts: 2
Joined: Sat Jun 23, 2007 2:55 am

Show login username

Post by Black-Chaos »

Forgive me if this is a totally wrong place to ask, but it's a liitle hard to know where to ask what around here.

I'm creating a code outside of the forums, and it will show your username after you logon in the top corner saying "Logged in as (username)'. I have almost all the code down, except the part that shows your username.

Code: Select all

<?PHP 

define('IN_PHPBB', true);
$phpbb_root_path = './bbs/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('ucp');
?>

<Javascript code here>

<?PHP

if ($user->data ['is_registered'])
{
echo "Logged in as (username). ";
echo '<BR><BR><a href="'.$phpbb_root_path.'/ucp.php?mode=logout&sid='.$user->data['session_id'].'&redirect='.$returnAddress.'">Logout</a>';
}
else{

echo "<DIV id=\"loginbox_button\"><table width=\"219\" border=\"0\">";
echo "<tr>";
echo "<span onmouseup=\"HideDIV('loginbox_button');DisplayDIV('loginbox_itself')\" style=\"cursor:pointer\"><img border=\"0\" align=\"left\" src=\"loginbutton.png\"></span> <a href=\"javascript:poptastic('/bbs/ucp.php?mode=register', 'Register');\"> <img border=\"0\" align=\"right\" src=\"registerbutton.png\"> </a>";
echo "</tr>";
echo "</table></DIV>";

echo "<DIV align=\"left\" id=\"loginbox_itself\" style=\"display:none\"><table width=\"219\" border=\"0\">";
echo "<tr>";
echo "<form action=\"./bbs/ucp.php?mode=login\" method=\"POST\">";
echo "<span class=\"genmed\">Username:</span> <input class=\"POST\" type=\"text\" name=\"username\" maxlength=\"30\" /><BR><span class=\"genmed\">Password:</span> <input class=\"POST\" type=\"password\" name=\"password\" maxlength=\"30\" /><BR><span class=\"gensmall\">Log me on automatically each visit </span> <input type=\"checkbox\" class=\"radio\" name=\"autologin\" /><BR><input type=\"submit\" class=\"btnmain\" name=\"login\" value=\"Login\" />";
echo "</form>";
echo "<BR>Make sure you refresh after you comeback to see your stuff, or after you logout...";
echo "</tr>";
echo "</table></DIV>";

}
?>
I don't know what to put in for

Code: Select all

echo "Logged in as (username). ";
in place of (username), to show your username. I'm just starting php, so it may seem obvious to you, but everything I put there just
A) breaks the page
or
B) when I'm logged in it says "Logged in as ." without any username.
Sorry if I sound really stupid.

User avatar
Aled
Registered User
Posts: 21
Joined: Tue Jan 30, 2007 4:47 pm
Location: United Kingdom
Contact:

Re: Show login username

Post by Aled »

Try $user->data['username'];

It has to be in a PHP echo tag. Like:

Code: Select all

<?php echo $user->data['username']; ?>
-Aled

Black-Chaos
Registered User
Posts: 2
Joined: Sat Jun 23, 2007 2:55 am

Re: Show login username

Post by Black-Chaos »

Aled wrote:Try $user->data['username'];

It has to be in a PHP echo tag. Like:

Code: Select all

<?php echo $user->data['username']; ?>
-Aled
lol, silly me. I forgot the data part. I always put $user->['username'] or something along those lines. :P

Anyway, thanks. :)

User avatar
Highway of Life
Registered User
Posts: 1399
Joined: Tue Feb 08, 2005 10:18 pm
Location: I'd love to change the World, but they won't give me the Source Code
Contact:

Re: Show login username

Post by Highway of Life »

phpBB3 has a very versatile templating system, you should consider using it instead of echo’s. ;)
Image

Post Reply