Jump to content

[SOLVED] $_SESSION help


trilbyfish

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.