Peterod Posted October 2, 2010 Share Posted October 2, 2010 Hi All I have a basic login system on my site. How would I go about displaying the current logged in user information from the session Id. its quite confusing..... <?php require 'Mysql.php'; class Membership { function validate_user($un, $pwd) { $mysql = New Mysql(); $ensure_credentials = $mysql->verify_Username_and_Pass($un, ($pwd)); if($ensure_credentials) { $_SESSION['status'] = 'authorized'; header("location: ../selfbuild/Controlpanel.php"); } else return "Please enter a correct username and password"; } function log_User_Out() { if(isset($_SESSION['status'])) { unset($_SESSION['status']); if(isset($_COOKIE[session_name()])) setcookie(session_name(), '', time() - 1000); session_destroy(); } } function confirm_Member() { session_start(); if($_SESSION['status'] !='authorized') header("location: login.php"); } } Just need to display the user name at the moment but am kinda not getting how its done. Do I just need <?php session_start(); echo $un Link to comment https://forums.phpfreaks.com/topic/215014-understanding-sessions/ Share on other sites More sharing options...
trq Posted October 2, 2010 Share Posted October 2, 2010 You will likely want to store the username within the $_SESSION array. function validate_user($un, $pwd) { $mysql = New Mysql(); $ensure_credentials = $mysql->verify_Username_and_Pass($un, ($pwd)); if ($ensure_credentials) { $_SESSION['status'] = 'authorized'; $_SESSION['username'] = $un; header("location: ../selfbuild/Controlpanel.php"); } return "Please enter a correct username and password"; } Then, on any page.... session_start(); if (isset($_SESSION['username'])) { echo "Hello {$_SESSION['username']}"; } Link to comment https://forums.phpfreaks.com/topic/215014-understanding-sessions/#findComment-1118438 Share on other sites More sharing options...
phpmady Posted October 3, 2010 Share Posted October 3, 2010 Hi, After you logged in .. $rows = mysql_query("select * from table_name where Username = $_SESSION['username']"); $row = mysql_fetch_array($rows); //if you want to store all the values of the user in session u can do like that $_SESSION['first_name'] = $row['first_name']; $_SESSION['last_name'] = $row['last_name']; $_SESSION['age'] = $row['age']; //wherever you want to display the user info ucan just call like this.. echo $_SESSION['age']; Hope you got it.. Thanks Link to comment https://forums.phpfreaks.com/topic/215014-understanding-sessions/#findComment-1118547 Share on other sites More sharing options...
Peterod Posted October 3, 2010 Author Share Posted October 3, 2010 what I actually want to do is take the username from the session, which is working now, thanks, and pit it into a form so that I can get different users to complete the form and i will know which user has done so. I will be able to figure that out now Thanks again guys. Link to comment https://forums.phpfreaks.com/topic/215014-understanding-sessions/#findComment-1118550 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.