Page 1 of 1

display name using sessions

Posted: Thu Jan 29, 2009 2:16 am
by kalp1200
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();
?>

Re: display name using sessions

Posted: Sun Feb 01, 2009 3:01 am
by jaoudestudios
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'])=="")
Where in the html?

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

Posted: Sun Feb 01, 2009 8:15 am
by jh_1981
<?=$_SESSION['userName'])?>

Re: display name using sessions

Posted: Sun Feb 01, 2009 9:46 am
by jaoudestudios
jh_1981 wrote:<?=$_SESSION['userName'])?>
Dont use that! That is sloppy!
Use

Code: Select all

<?php echo $_SESSION['userName']); ?>