display name using sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kalp1200
Forum Newbie
Posts: 19
Joined: Tue Aug 26, 2008 8:57 pm

display name using sessions

Post 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();
?>
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: display name using sessions

Post 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']
jh_1981
Forum Newbie
Posts: 22
Joined: Fri Jan 30, 2009 6:21 pm

Re: display name using sessions

Post by jh_1981 »

<?=$_SESSION['userName'])?>
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: display name using sessions

Post by jaoudestudios »

jh_1981 wrote:<?=$_SESSION['userName'])?>
Dont use that! That is sloppy!
Use

Code: Select all

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