slinkfresh
slinkfresh

Reputation: 63

unable to set $_SESSION variable with PHP variable

Here is where I am setting my session variables.

function validateUser()
{
session_regenerate_id (); //this is a security measure
$_SESSION['user'] = $_POST['username'];
$_SESSION['valid'] = 1;
$_SESSION['firstname'] = $firstname;
$_SESSION['lastname'] = $lastname;
}

This is what print_r ($_SESSSION) echos.

Array ( [user] => aboshart [valid] => 1 [firstname] => [lastname] => )

If I echo $firstname and $lastname I get the proper values. What am I doing wrong?

Upvotes: 0

Views: 45

Answers (1)

Kai Qing
Kai Qing

Reputation: 18833

You're not passing $firstname or $lastname to the function.

function validateUser($firstname, $lastname)
{
    session_regenerate_id (); //this is a security measure
    $_SESSION['user'] = $_POST['username'];
    $_SESSION['valid'] = 1;
    $_SESSION['firstname'] = $firstname;
    $_SESSION['lastname'] = $lastname;
}

$_POST and $_SESSION should be within scope but the others aren't

Upvotes: 3

Related Questions