I am trying to echo a welcoming message of Welcome (the user's name)! and I have done this fine on a php file just plain flat out echoing it. On my index.html file however when I use the same code trying to surround it with a div it does not work... Is it my concatenation? Why is this and how can I fix it?
<!---Sale Box--->
<center>
<div id="box">
<?php
session_start();
echo '<div id="text"> Welcome' . $_SESSION['username']. "</div>"
?>
</div>
</center>
you must use session_start
before any output.
http://php.net/manual/en/function.session-start.php : " Note: To use cookie-based sessions, session_start() must be called before outputing anything to the browser." .
change index.html to index.php
PHP cant be parsed in .html
-files. Only if you reconfigure your Apache-Server to handle .html
as same as he does with .php
.
So your page must be index.php
instead of index.html
Also you should take care to run this on a server where a apache is running or may install a local apache server to parse php. See xampp
After this you have to echo like this (one possibility)
<?php session_start(); ?>
<!---Sale Box--->
<center>
<div id="box">
<?php echo "<div id='text'>Welcome {$_SESSION['username']}</div>"; ?>
</div>
</center>