Message returning Session username using str_replace

Asked

Viewed 621 times

0

I need help putting the user name at the top of the page. In php I managed to do, (if you echo "$userName" it works) but loses all formatting, so I need to replace it in html. Look at

if (Session::getValue('logado')):

            switch (Session::getValue('departamento')) {
                case '1':

                    $menu = 'menu/admin.html';

                    $nomeusuario = $_SESSION['nome'];

                    $string = 'Olá ' . $nomeusuario . ' seja bem vindo!';

                    $nova = str_replace('#TMSG#', $nomeusuario, $string);

                    var_dump($nova);
  • 1

    It doesn’t seem to make any sense. After all, what do you want to replace? How are you currently doing and how do you want to replace it?

  • Not replacing anything with anything and there are clotheslines unused.

1 answer

1

So I know you want in str_replace, but it is possible to do echo:

you must go to the desired part of the site and use:

<?php 
  echo "$nomeusuario seja bem vindo(a)!";
?>

Ta but it will go without formatting

Simple to use CSS:
EXAMPLE:
HTML:

<div id="saudacao">
<?php 
  echo "$nomeusuario seja bem vindo(a)!";
?>
</div>

CSS:

#saudacao {
    color: red;
    font-family: Arial;
    font-size: 20px;
}

To put a size put inside a one <h>

As I said at the beginning, I know this is not how you asked but this is how I always used it. I hope I’ve helped.

  • Problem is that I tried to do so, but it didn’t work. Here’s how I did: <? php echo "$username is welcome(a)!" ; ? > <div class="title-bar" data-Responsive-toggle="main-menu" data-Hide-for="medium"> <button class="menu-icon" type="button" data-toggle></button> <div class="title-bar-title">Menu</div> </div> .

  • I think it’s pq you have to declare the variable $nomeusuario before, try like this: <div id="saudacao">&#xA;<?php $nomeusuario = $_SESSION['nome'];&#xA; echo "$nomeusuario seja bem vindo(a)!";&#xA;?>&#xA;</div>

  • It didn’t work either. Neither: $username = $_SESSION['name']; print $username;

  • 1

    @Eduehi as Gustavox said, fixes the problem comes because the variable is not declared for Php so it is as it does not exist.

  • It doesn’t work, I don’t know why. I’ve tried it like this. But I think the only way will be with replace even.

  • @Eduehi Vish here has never given problem, this is strange. But with replace should work, but n use it for a long time so I have to do a search

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.