Click here to Skip to main content
15,868,292 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i cant echo out the username next to welcome under div topline in



XML
<?php
session_start();
?>

<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" href="Styles/header_main.css">
</head>
<body>
    <div class="wrapper col0">
        <div id="topline">
            <p>Welcome, <?php echo $_SESSION['name'];?>!</p>
            <ul>
                <li><a href="#">CHANGE PASSWORD</a></li>
                <li class="last"><a href="logout.php">LOGOUT</a></li>
            </ul>
            <br class="clear" />
        </div>
    </div>
    <div id="container">

    </div>
</body>
</html>
Posted
Comments
walterhevedeich 14-Oct-13 0:06am    
A lot of things to see there. Have you checked if the session variable has a value? Does it have errors when the page is rendered?
Akinmade Bond 14-Oct-13 3:27am    
Well, $_SESSION['name'] is empty apparently, have you set it before?
Nico_Travassos 16-Oct-13 3:03am    
its fixed my mistake i forgot to set $_SESSION['name']

thanks

Well, first you should see Secure Sessions in PHP[^]

When the user logs in, save the username in a session. Like so


PHP
//Start a session.
secure_session_start();

//........some processing

//After you have checked that the username is correct.
$_SESSION['name'] = sanitized_username;
//Save some other things you might need like login key.
$_SESSION['login_key'] = user_login_key;

?>

HTML
<html>
<head>
    <title>My document title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" href="Styles/header_main.css">
</head>
<body>
    <div class="wrapper col0">
        <div id="topline">
            <p>Welcome, <?php echo $_SESSION['name'];?>!</p>
            <ul>
                <li><a href="#">CHANGE PASSWORD</a></li>
                <li class="last"><a href="logout.php">LOGOUT</a></li>
            </ul>
            <br class="clear" />
        </div>
    </div>
    <div id="container">
 
    </div>
</body>
</html>

 
Share this answer
 
najmudrejsi na svete si kamos, díky za pomoc
 
Share this answer
 
Comments
Richard Deeming 21-Jan-22 4:20am    
If you want to reply to a solution, click the "Have a Question or Comment?" button under the solution and post a comment.

Do not post your comment as a "solution" to the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900