0

I am not sure why the variable username is not being returned in the session. When the user logs in, I start the session:

$username = trim($_POST['username']);
if(!isset($_SESSION)){ session_start(); }
$_SESSION[$this->GetLoginSessionVar()] = $username;

On the user's welcome page, when I run the echo command, I see the proper variable being returned. But I'm not sure why the return statement isn't working. I have the following in my PHP file:

function UserName()
{

    return  isset($_SESSION['name_of_user']) ? $_SESSION['name_of_user'] : "Unknown User" ;
    //echo $_SESSION['name_of_user'];
}

In my html, I have:

Welcome back <?PHP $fgmembersite->UserName(); ?>!

I also checked the session ID, and it's also being generated properly. Can you please help me understand what I'm doing wrong?

hakre
  • 193,403
  • 52
  • 435
  • 836
JK0124
  • 375
  • 2
  • 4
  • 14

5 Answers5

5

Is fgmembersite an object and have it the function called UserName ?

If yes, you simply miss an echo

<?PHP echo $fgmembersite->UserName(); ?>
DonCallisto
  • 29,419
  • 9
  • 72
  • 100
3

You must add echo or print so should look like this;

<?PHP echo $fgmembersite->UserName(); ?>
Darren Burgess
  • 4,200
  • 6
  • 27
  • 43
2

You need to print out your variable. Use

Echo or print

Pier-Alexandre Bouchard
  • 5,135
  • 5
  • 37
  • 72
2

Possibly you should add output:

<?php print $fgmembersite->UserName(); ?>
VisioN
  • 143,310
  • 32
  • 282
  • 281
1

If you are using the script I think you are using, you need to look through fg_membersite.php at the line that says:

function CheckLoginInDB($username,$password)

whithin that line you should have a MySQL statement:

$qry = "SELECT etc...

When I tried to add UserAvatar I was able to do that by adding it to that MySQL string.

On a side note, I too am having trouble with adding UserName, and for the life of me I can't figure out why it would work any different than my previous workaround, yet somehow it is, but I am still convinced something in that file will do the trick eventually.

Edited:

Ok i got it, just do this:

echo $fgmembersite->UserName($username);

The username will pop right out. I have no idea why, i don't know enough php to explain it, but i can only assume this will get you going.