echo '<li><a href="signup.html"><span class="glyphicon glyphicon-user"></span>Welcome echo $_SESSION["username"];</a></li>';
In the above code it is not displaying username variable.. instead it is simply echoing Welcome $_SESSION["username"];
FYI.. I have used session.start() in both the files
But how to display Welcome 'username'
The part Welcome echo $_SESSION["username"];
is simply a STRING
and would be echoed verbatim without any Evaluation, Processing or Parsing. And, by the way: You don't use an echo
Statement within an echo
statement. That should be like SAYING GOOD MORNING IN ENGLISH & GERMAN AT THE SAME TIME THROUGH THE SAME ONE SINGLE MOUTH
: LOL :-)
You should have used Double Quotes to surround the String you wished to echo out and then use single quotes for the HTML DOM Element Attributes like "class" or "HREF". That way you, you could very easily echo your String without much fuss. Here's how:
<?php
echo "<li>
<a href='signup.html'>
<span class='glyphicon glyphicon-user'></span>Welcome {$_SESSION['username']}
</a>
</li>";
You have an error. you should close quotes.
echo '<li><a href="signup.html"><span class="glyphicon glyphicon-user"></span>Welcome' .$_SESSION["username"].'</a></li>';
If still doesn't show the username: Turn on error_reporting or use var_dump to cehck if variable is set
<?php
error_reporting(-1);
<?php
var_dump($_SESSION);
and just note about templating. If you use this in a view (most of code is html) then try to use php temlating
<li>
<a href="signup.html">
<span class="glyphicon glyphicon-user"></span>Welcome <?= $_SESSION["username"] ?>
</a>
</li>
Try this echo '<li><a href="signup.html"><span class="glyphicon glyphicon-user"></span>Welcome '. $_SESSION["username"] .'</a></li>';