-1

Hi really quick question, i was wandering how i can output a string alongside a username which is generated using sessions

i want the code to say something like : "Welcome, (username)"

This is my code so far which outputs the username of the person logged in, but i want to add "welcome" in front of the username.

<?php
   if (isset($_SESSION['username'])){
   echo '<div id="welcome_msg">'  .$_SESSION['username']. '</div>';
                                }
?>
Gavin Lau
  • 19
  • 1
  • 9

2 Answers2

1

You can add non-PHP content within quotes in echo statement like:

   echo '<div id="welcome_msg">Welcome '  .$_SESSION['username']. '</div>';
mesutozer
  • 2,839
  • 1
  • 12
  • 13
  • ahh okay thank you for the reply, you can tell im very new to this stuff aha :) when 12 mins is up i can put this as the correct answer – Gavin Lau Apr 06 '14 at 11:36
  • You're welcome. You can refer to following answer http://stackoverflow.com/questions/1100354/how-can-i-echo-html-in-php for more information – mesutozer Apr 06 '14 at 11:39
0
<?php
  if(isset($_SESSION['username']))
  {
      echo "<div id='welcome_msg'>Welcome ".$_SESSION['username']."</div>";
  }

If you may want, you can even style the username with bold, or italic or underline with , and respectively. e.g. to bolden the username;

<?php
  if(isset($_SESSION['username']))
  {
      echo "<div id='welcome_msg'><b>Welcome ".$_SESSION['username']."</b></div>";
  }
Kimutai
  • 1,022
  • 11
  • 15