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 Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 30, 2008 Share Posted March 30, 2008 $_SESSION['surname'] is not set. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 31, 2008 Share Posted March 31, 2008 what is $row? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.