-
showing username
Im trying to display a logged in user's username
I have a login script, i have a cookie, and i know that $user is the username used in the cookie. My header is modified so that i can use $user in the file, but it wont work...ill post the code:
PHP Code:
<div class="leftc">
<div class="blockTitlel">Member Panel</div>
<div class="blockContentl">
<?php
echo('Welcome back, '.$user.'.');
?>
<BR><BR>
<a href="newpost.php">Post!</a><BR>
<a href="logout.php">Logout</a><BR>
</div>
</div>
This file is used as an include to my index.php...when i browse to that page, i see: Welcome back, .
Could you guys help me please?
-
Re: showing username
Hmm, you will have to post more of the code. Apparently the variable is empty.
-
Re: showing username
O.K. Here's some more code (the cookie is there, i've checked it...twice!
here my code that's in all of my header's:
PHP Code:
if ($_SESSION['logged_in'] != 1 && isset($_COOKIE['login_cookie'])) {
list($user, $pass) = explode('[]', $_COOKIE['login_cookie']);
$qu = mysql_query("SELECT `user_password` FROM `members` WHERE `username` = '".addslashes($user)."'");
if (mysql_num_rows($qu) == 1) {
$passw = mysql_fetch_object($qu);
if ($passw->user_password == $pass) {
$_SESSION['logged_in'] = 1;
$_SESSION['username'] = $user;
$_SESSION['password'] = $pass;
}
}
}
if(!isset($_SESSION['username']) && !isset($_SESSION['password'])) {
$_SESSION['logged_in'] = 0;
$user = "Guest";
}
?>
-
Re: showing username
-
Re: showing username
-
Re: showing username
Are you sure that:
list($user, $pass) = explode('[]', $_COOKIE['login_cookie']);
works?
-
Re: showing username
echoing the session worked for me...thx...you're a lifesaver
PS: mod can close this...