Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
Change user image based on who's logged in

I'm currently working on a login portal.

I already set the log in and log out functions and placed a session start button on every page.

My problem now is that I would like to update the user image based on the identity of who is logged in.

I'm using a template my boss chose, and this is the code where the image is:

<span>
    <img src="../../global/portraits/5.jpg" alt="...">
 </span>

Just a simple <img> tag with the link where the image is.

My project is in an html file with php implemented, and I tried to do this in the <span> tag, instead of <img>:

<?php
        $W = ["Raffaella", "Milena", "Domiziana"];
        $M = ["Umberto", "Domenico"];
    
        if ($_SESSION["nome"] == $W) {
                echo '<img src="W.jpg">';
        } else if ($_SESSION["nome"] == $M){
                echo '<img src="M.jpg">';
        }
?>

where $_SESSION["nome"] represents the current user logged in. However, it doesn't do anything, not even producing an error.

Can someone explain how I can do it correctly, please? I'm new to php and trying to understand by studying alone on the internet

I was also considering JavaScript for this work (instead of PHP), but I don't know where to start

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It looks like both $W and $M are array of names, rather than a single user, if that's the case, I assume you're trying to determine if a user is in that array. In PHP, you can use:

in_array($_SESSION["nome"], $W)

https://www.php.net/manual/en/function.in-array.php

which will return true/false.

        if (true === in_array($_SESSION["nome"], $W)) {
                echo '<img src="W.jpg">';
        } else if (true === in_array($_SESSION["nome"], $M){
                echo '<img src="M.jpg">';
        }

But, this only gives two separate images for up to 5 unique names, and I'm not sure if that's what you're going for.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda