How to insert username or user fields into a page

meanster99

Well-known member
Hi,

I wanted to add the current username into the homepage somewhere. I would love to do this with an HTML custom page if possible, but I'm not sure it is? I looked at creating a custom PHP page for it and read the example.php, and enabled custom php pages in config.php. The example.php says that I can add:

[pre]
$_SESSION['logged_user_infos_ar']["username_user"]
[/pre]

However, when I tried adding it, nothing appeared. I'm a noob when it comes to php, but this is what I wrote and nothing appeared:

[pre]
<?php
echo $_SESSION['logged_user_infos_ar']["username_user"];
[/pre]

What am I doing wrong please? Ideally, I'd like to actually display the values in 'first_name_user' and 'last_name_user', rather than the username itself. How would I do that? Could I just change it to $_SESSION['logged_user_infos_ar']["first_name_user"]["last_name_user"]? What is the correct syntax to use in PHP?

Thanks,
Matt
 

eugenio

Administrator
Staff member
The HTML page just displays HTML, there is no PHP interpretation. I would put

[pre]
if (isset($_SESSION['logged_user_infos_ar']["username_user"])){
echo $_SESSION['logged_user_infos_ar']["username_user"];
}
[/pre]


somewhere in header.php


You don't have the name of the users in session unless you change the get_user_infos_ar_from_username_password() function. You only have the username.
 
Top