tags:

views:

84

answers:

4

Hello,

I have some php code $_SESSION['username'] and I need to display it using html with something like <p>the username here</p>. I heard you might be able to do this using echo in PHP but Im not sure how. Thanks for any help.

+2  A: 
<?php echo '<p>'.$_SESSION['username'].'</p>'; ?>
Finbarr
+4  A: 

If I understood you correctly, I believe you are looking for:

<p><?php echo $_SESSION['username']?></p>
Brian Wigginton
+1  A: 

Check out the documentation:

http://www.php.net/manual/en/tutorial.useful.php

webbiedave
+7  A: 
echo '<p>' . $_SESSION['username'] . '</p>';

or

<p><?php echo $_SESSION['username'] ?></p>

You should really run it through htmlspecialchars to avoid breaking your HTML syntax (for example if the user's name contains </p> or something, or if they attempt an XSS attack):

echo '<p>' . htmlspecialchars($_SESSION['username']) . '</p>';
Will Vousden
I'll try that thanks
happyCoding25
You should always use `htmlspecialchars` to put text into HTML, whether it came from the user or not. It's a matter of correctness as much as security! (Except of course in the case where you deliberately want to inject literal HTML, which is comparatively rare.)
bobince
@bobince: You're right, of course. I've updated my answer :)
Will Vousden