How do I print the $_SESSION['...']
in my external html? It would be for Welcoming the user on my webpage.
My PHP and HTML are two separate files. I wanted to show the username of the account that is currently logged on in the webpage.
session_start();
$_SESSION['user_name']=$username;
That's what is written in my php file. But how do I print it on HTML?
Thanks
You can include the PHP within your HTML but would need to use the file extension '.php' instead of '.html' (unless you inform your web server to parse html files as PHP), because in this case it is not mixing concerns.
<?= $_SESSION['user_name']; ?>
You could use the full PHP tag also and echo the value. But remember to also escape the value using htmlentities() like so:
<?= htmlentities($_SESSION['user_name']); ?>
Sorry for not being more clear...The above examples would assume you had session_start() somewhere earlier in your code, otherwise it would not be available.