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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.