php - pull from session user info -
ok have user login uses email address , password when login want pull there session data
like username , else there record
i use
<?php if(isset($_session['email'])) { echo $_session['email']; } ?>
it works , pulls there email address how there username? tried changing email username , nothing shows
my login setup
/* login functions */ function login_user($email, $password, $remember) { $sql = "select user_pwd, uid users user_email = '" . escape($email) . "' , active = 1"; $result = query($sql); if (row_count($result) == 1) { $row = fetch_array($result); $db_password = $row['user_pwd']; if (password_verify($password, $db_password)) { if ($remember == "on") { setcookie("email", $email, time() + 86400,'/'); } $_session['email'] = $email; return true; } else { return false; } return true; } else { return false; } } /* user logged in function */ function logged_in(){ if (isset($_session['email']) || isset($_cookie['email'])) { return true; } else { return false; } }
you need make small changes in login_user() function.
function login_user($email, $password, $remember) { $sql = "select user_pwd, uid, username users user_email = '" . escape($email) . "' , active = 1"; $result = query($sql); if (row_count($result) == 1) { $row = fetch_array($result); $db_password = $row['user_pwd']; if (password_verify($password, $db_password)) { if ($remember == "on") { setcookie("email", $email, time() + 86400,'/'); } $_session['email'] = $email; $_session['username'] = $row['username']; return true; } else { return false; } return true; } else { return false; } }
now can use below code username in session. make sure must have username field in users table.
if(isset($_session['username'])) { echo $_session['username']; }
Comments
Post a Comment