Hi guys, I have this piece of code, how do I display the name of the user in the html part
<?php
include("php/connect.php");
session_start();
if (isset($_SESSION['userName'])=="")
{
header("Location:Home.php?msg=Login_Required");
}
?>
<table border="1" width="78%" id="table4" bordercolor="#CCFF33" style="border-style: solid; border-width: 1px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px">
<tr>
<td bgcolor="#CCFF33" colspan="2">Your PHPSESSID is: <?php echo ......... ?>
</td>
</tr>
</table>
</div></body>
<?php
include("footer.php");
?>
</head>
</html>
<?php
mysql_close();
?>
display name using sessions
Moderator: General Moderators
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: display name using sessions
Where in the html?kalp1200 wrote:Hi guys, I have this piece of code, how do I display the name of the user in the html part
Code: Select all
session_start(); if (isset($_SESSION['userName'])=="")
Your php line above does not make any sense! isset returns a true or false not an empty - it may still work because php is forgiving but it is ambiguous so could give you problems.
To display the username just use $_SESSION['userName']
Re: display name using sessions
<?=$_SESSION['userName'])?>
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: display name using sessions
Dont use that! That is sloppy!jh_1981 wrote:<?=$_SESSION['userName'])?>
Use
Code: Select all
<?php echo $_SESSION['userName']); ?>