cmazur Posted December 5, 2006 Share Posted December 5, 2006 Ok, I need to keep the username and user_id of my user who has logged in.This is my first attempt at using sessions, thus I am not sure why this is not working.The first time the user logs in, any old sessions are destroyed and a new session is started setting the username and id.When the user returns to the page , the username and id should be stored in the session array.Needless to say, I think it's my syntax having to do with the sessions...[code] if (isset($_POST["login"])) { //Get form data values $username = $_POST["username"]; $password = $_POST["password"]; //Validate the user $id = validate_user(get_user($username, $password), $username); if($id != -1) { //Unset any prior session variables unset($_SESSION['username']); unset($_SESSION['id']); //Destroy any prior session session_destroy(); //Start new session session_start(); $_SESSION['username'] = $username; $_SESSION['id'] = $id; } } else { //Get the logged in user's information session_start(); $username = $_SESSION['username']; $id = $_SESSION['id']; print("user: $username <br />id: $id<br />"); } [/code] Link to comment https://forums.phpfreaks.com/topic/29465-using-sessions-should-be-simple/ Share on other sites More sharing options...
fert Posted December 5, 2006 Share Posted December 5, 2006 you need to have session_start at the top of the page. Link to comment https://forums.phpfreaks.com/topic/29465-using-sessions-should-be-simple/#findComment-135224 Share on other sites More sharing options...
cmazur Posted December 5, 2006 Author Share Posted December 5, 2006 top of the page meaning that i need a php script in the header of my XHTML or at the top of the body of my XHTML?just a little confused.thanks for the help. Link to comment https://forums.phpfreaks.com/topic/29465-using-sessions-should-be-simple/#findComment-135225 Share on other sites More sharing options...
fert Posted December 5, 2006 Share Posted December 5, 2006 [code]<?phpsession_start();?><html><head><title>Title</title>...[/code]like that Link to comment https://forums.phpfreaks.com/topic/29465-using-sessions-should-be-simple/#findComment-135228 Share on other sites More sharing options...
cmazur Posted December 5, 2006 Author Share Posted December 5, 2006 ok, that was simple.thanks for all of the help. Link to comment https://forums.phpfreaks.com/topic/29465-using-sessions-should-be-simple/#findComment-135229 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.