trilbyfish Posted March 30, 2008 Share Posted March 30, 2008 i have a logged in page which when a user logs in, greets them by using their firstname from the session that has been created. For some reason it wont print the surname of the person who has just logged in, only the firstname. <? session_name('visit'); session_start(); //check for session value if(!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT']))){ // Redirect the user to the loggedin.php page. // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/members.php'; header("Location: $url"); exit(); // Quit the script. } //set up message echo "<h1>Logged In!</h1>"; echo "<p>You are now logged in, {$_SESSION['firstname']} {$_SESSION['surname']}!</p>"; ?> Please if someone could help i would be very grateful Thanks in advance Link to comment https://forums.phpfreaks.com/topic/98694-solved-_session-help/ Share on other sites More sharing options...
BlueSkyIS Posted March 30, 2008 Share Posted March 30, 2008 $_SESSION['surname'] is not set. Link to comment https://forums.phpfreaks.com/topic/98694-solved-_session-help/#findComment-505092 Share on other sites More sharing options...
trilbyfish Posted March 31, 2008 Author Share Posted March 31, 2008 in the page of code that defines the session, the login page, i have the following code // Set the session data & redirect. session_name ('visit'); session_start(); $_SESSION['id'] = $row[0]; $_SESSION['firstname'] = $row[1]; $_SESSION['surname'] = $row[2]; $_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']); // Redirect the user to the loggedin.php page. // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/loggedin.php'; header("Location: $url"); exit(); // Quit the script. i added in the $_SESSION['surname'] = $row[2]; when i realised i had missed it out, but when i login it still only shows the firstname on the welcome message. Link to comment https://forums.phpfreaks.com/topic/98694-solved-_session-help/#findComment-505852 Share on other sites More sharing options...
BlueSkyIS Posted March 31, 2008 Share Posted March 31, 2008 what is $row? Link to comment https://forums.phpfreaks.com/topic/98694-solved-_session-help/#findComment-505887 Share on other sites More sharing options...
trilbyfish Posted April 1, 2008 Author Share Posted April 1, 2008 $row is the array i think, or what slot of the session array it is in, i think. i can print the id of the logged on user using this, so i dont know why the surname cant be printed Link to comment https://forums.phpfreaks.com/topic/98694-solved-_session-help/#findComment-506824 Share on other sites More sharing options...
trilbyfish Posted April 1, 2008 Author Share Posted April 1, 2008 please help, i really cant think what the problem is. Link to comment https://forums.phpfreaks.com/topic/98694-solved-_session-help/#findComment-506863 Share on other sites More sharing options...
trq Posted April 1, 2008 Share Posted April 1, 2008 Can we see where you define $row including where your query that authenticates each user? Link to comment https://forums.phpfreaks.com/topic/98694-solved-_session-help/#findComment-506868 Share on other sites More sharing options...
trilbyfish Posted April 1, 2008 Author Share Posted April 1, 2008 solved! silly me! i hadnt selected surname from the sql table which i didnt post in the above code i have now added surname to the SELECT query, and it works! Link to comment https://forums.phpfreaks.com/topic/98694-solved-_session-help/#findComment-506871 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.