Khalil Ghâñmî

0 %
Khalil Ghâñmî
Développeur full-stack
  • Residence:
  • City:
  • Age:
  • HTML 5 / CSS 3
  • Bootstrap
  • JavaScript / Jquery/Ajax
  • ReactJS
  • API
  • Angular
  • PHP/Mysql
  • Python
  • Java
  • Wordpress
  • OpenCart
  • Illustrator | Photoshop | Premier Pro | Animate
  • OVH | Godaddy | Vipdomaine | Zenhosting | LWS | Hostgator
  • Cpanel
  • Google Search | Google sheets | Google docs | Office

Retrieve the name of the logged in user.

24 August 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 Non classé, PHPTags:
Write a comment