Khalil Ghâñmî

0 %
Khalil Ghâñmî
Front-end developer
  • Residence:
    Tunis
  • City:
    Bardo
  • Age:
    28
French
English
arabe
HTML 5 / CSS 3
JavaScript / jquery
PHP / MYSQL
WordPress
OpenCart 3
Vegas Pro
Adobe premier pro
  • Bootstrap, Materialize
  • Stylus, Sass, Less

Retrieve the name of the logged in user.

24 août 2022

Good evening,

Let me briefly explain my problem.
I’m looking from a WordPress site to retrieve the name of the logged in user.

For this I use the ShortCode Exec PHP plugin which allows me to create a shortcode with PHP code. So I put this following code:

Coded :

global $current_user;
global $user_not_logged;
$user_not_logged="Vous n'êtes pas connecté !";                  // définition variable si utilisateur non connecté
if ( isset($current_user) ) {
    $user = $current_user->display_name;                        // recupère le nom de l'utilisateur connecté
    $text = "Bonjour". " " .$user. ",";
    echo $text;                                                 // affichage de l'utilisateur connecté
}

I therefore retrieve the name of the connected user.
My question is, how to use this variable. Indeed locally I managed to create a .txt file which allows me to store the user’s name on the C:\ disk then to read it again in another script. But this method does not work online.
I’m looking to use this variable in a script that allows the user to view a personalized page based on their name.
But how to do when two users connect at the same time.

I am able to register a name in a database but what if two users connect at the same time. One should not be able to see the page of the other.

I tried to use cookies but without success.

Since I’m dry on this question, I would like to ask for your help.

Thanks in advance.

Posted in PHPTags:
Write a comment