Getting current signed in user PHP

zio

New Member
I am having the hardest time trying to figure out how to echo the current user in PHP after logging in. I know it's something simple but I can't figure it out. When I do \[code\]<?php echo $_SESSION['usersignedin']; ?>\[/code\] I get "username". Thanks in advance for your help. Here is what I am using. index.php (sign in page)\[code\]<?phprequire_once('include.php');$error = '';$form = (isset( $_POST['submit']) ? $_POST['submit'] : null);$username = (isset( $_POST['username']) ? $_POST['username'] : null);$password = (isset( $_POST['password']) ? $_POST['password'] : null);if( isset($form) ) {if( isset($username) && isset($password) && $username !== '' && $password !== '' ) {$sql = mysql_query("SELECT * FROM `members` WHERE username='$username' andpassword='$password';");if( mysql_num_rows($sql) != 0 ) { //success$_SESSION['logged-in'] = true;header('Location: signedin.php');exit;} else { $error = "Invalid Username or Password"; }} else { $error = 'Username and Password not filled out';}}?><html><head> <title>Sign In</title></head><body><center><h1>Please sign in.</h1></center> <div id="pagewrapper"> <!-- Start pagewrapper div --><div id="login_wrapper"> <div id="login"> <form action="<?php $PHP_SELF; ?>" method="post" > <table> <tr> <td>Username:</td> <td><input type="text" name="username" value="http://stackoverflow.com/questions/15915112/<?php echo"$username";?>" /><br /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password" /><br /></td> </tr> </table> <br> <td> <input name="submit" type="submit" value="http://stackoverflow.com/questions/15915112/Login" /> </td><?phpecho "<br /><span style=\"color:red\">$error</span>";?> </form> </div> </div> <!-- End login wrapper --></div> <!-- End pagewrapper div --></body></html>\[/code\]signedin.php (page after signing in)\[code\]<?phprequire_once('include.php');if ( !isset($_SESSION['logged-in']) || $_SESSION['logged-in'] !== true) {header('Location: index.php');exit;}$sql = mysql_query("SELECT * FROM `members` WHERE username='$username' andpassword='$password';");?><html><head> <title>Sign in</title></head><link rel="stylesheet" type="text/css" href="http://stackoverflow.com/questions/15915112/style.css"><body><body class="home"> <div id="header"> <div id="welcome"> <p>Hi, <?php echo $_SESSION['usersignedin']; ?> ! <a href="http://stackoverflow.com/questions/15915112/logout.php">logout</a></p> </div> <div id="links"><ul></ul> </div> </div> <div id="content">&nbsp;<div id= "stuff"><h3 class="stuffheader">Header</h3><p> Text </p> </div> <div id= "stuff"><h3 class="stuffheader">Header</h3> </div></div></body></html>\[/code\]include.php (DB Stuff)\[code\]<?phpsession_start();$host = "localhost";$username = "root";$password = "root";$db = "intranet";@mysql_connect($host,$username,$password) or die ("error");@mysql_select_db($db) or die("error");?>\[/code\]
 
Top