Hi,
I have created a login system for my website using PHP and mySQL. Now I would like it to display the user's username in various places in the site (eg. Welcome 'username'!) after the user logs in. I'm just getting started with PHP. Any help would be greatly appreciated!
Here's the code for my login.php page:

<?php
session_start();
require_once 'classes/Membership.php';
$membership = new Membership();

// If the user clicks the "Log Out" link on the index page.
if(isset($_GET['status']) && $_GET['status'] == 'loggedout') {
	$membership->log_User_Out();
}

// Did the user enter a password/username and click submit?
if($_POST && !empty($_POST['username']) && !empty($_POST['pwd'])) {
	$response = $membership->validate_User($_POST['username'], $_POST['pwd']);
}


?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login to access the secret files!</title>
<link rel="stylesheet" type="text/css" href="css/default.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</head>

<body>
<div id="login">
	<form method="post" action="">
    	<h2>Login <small>enter your credentials</small></h2>
        <p>
        	<label for="name">Username: </label>
            <input type="text" name="username" />
        </p>

    <p>
    	<label for="pwd">Password: </label>
        <input type="password" name="pwd" />
    </p>

    <p>
    	<input type="submit" id="submit" value="Login" name="submit" />
    </p>
</form>
<?php if(isset($response)) echo "<h4 class='alert'>" . $response . "</h4>"; ?>
</div><!--end login-->
</body>
</html>

And the code for my index.php page, which is only accessible after the user logs in:

<?php

require_once 'classes/Membership.php';
$membership = New Membership();

$membership->confirm_Member();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/default.css" />

<!--[if lt IE 7]>
<script type="text/javascript" src="js/DD_belatedPNG_0.0.7a-min.js"></script>
<![endif]-->


<title>Untitled Document</title>



</head>

<body>

<div id="container">
	<p>
    	You've reached the page that stores all of the secret 	launch codes!
    </p>
    <a href="login.php?status=loggedout">Log Out</a>
</div><!--end container-->

<div id="welcome"><span class="welcomeHead">Welome, <?= $_SESSION['MM_Username'] ?>.</span><br />

</body>
</html>

To create this login system, I used a very helpful video tutorial at http://net.tutsplus.com/articles/news/how-to-build-a-login-system-for-a-simple-website/

    The way I see it....you can just pass the username to your index.php. Or you can pass some user_id or so, if you have that in the database.

    Just invoke something like following after your validate_User and call something like

            redirectTo("/index.php?username=".
                       $username"); 

      Doesn't that [font=monospace]$membership[/font] object you're using have a method to get the username? Or doesn't it keep such information?

        Thanks for the quick reply.
        No, its still not working - I'm not sure if I put the code you told me to insert in the right place. Here's the login.php page:

        <?php
        session_start();
        require_once 'classes/Membership.php';
        $membership = new Membership();
        
        // If the user clicks the "Log Out" link on the index page.
        if(isset($_GET['status']) && $_GET['status'] == 'loggedout') {
        	$membership->log_User_Out();
        }
        
        // Did the user enter a password/username and click submit?
        if($_POST && !empty($_POST['username']) && !empty($_POST['pwd'])) {
        	$response = $membership->validate_User($_POST['username'], $_POST['pwd']);        redirectTo("/index.php?username=".
                           $username);  
        } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Login to access the secret files!</title> <link rel="stylesheet" type="text/css" href="css/default.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script> <script type="text/javascript" src="js/main.js"></script> </head> <body> <div id="login"> <form method="post" action=""> <h2>Login <small>enter your credentials</small></h2> <p> <label for="name">Username: </label> <input type="text" name="username" /> </p> <p> <label for="pwd">Password: </label> <input type="password" name="pwd" /> </p> <p> <input type="submit" id="submit" value="Login" name="submit" /> </p> </form> <?php if(isset($response)) echo "<h4 class='alert'>" . $response . "</h4>"; ?> </div><!--end login--> </body> </html>
          Write a Reply...