I was looking through my registration and login form, and the thing that is bothering me is that I have several sessions defined for individual variables of each form. Here is what I am talking about:
Part of my registration form:
$pass = md5($pass);
$regSQLI = "INSERT INTO users (id, email, birth_date, first_name, last_name, password, sign_up_date, activated) VALUES ('','$em','$bday','$fn','$ln','$pass','$sud','0')";
$regQuery = mysqli_query($con, $regSQLI);
//variables that will be passed over from the register fields to forthcoming sessions
$_SESSION["email_login"] = $em;
$_SESSION["first_name"] = $fn;
$_SESSION["last_name"] = $ln;
Part of my login form:
if ($userCount == 1) { //if the search finds a matching record of the login input form
while( $row = mysqli_fetch_assoc($sqli)) { // use fetch_assoc
$id = $row["id"];
}
$_SESSION["email_login"] = $email_login;
$_SESSION["first_name"] = $fn;
$_SESSION["last_name"] = $ln;
header("location: home.php");
exit();
}
else {
echo '<div id="regerrormsg">Login information is invalid. </div>';
}
}
Everything works, but I want to know whether I can save some performance by cleaning up having to evoke multiple sessions. The reason why I have multiple sessions is because even though users will be using their emails to register and login, the system will address/echo them by their names:
<?php
echo $_SESSION["first_name"]." ".$_SESSION["last_name"].".";
?>
Is there a way to where I can just have one session variable (perhaps email) as a validator and retrieve data from the database that corresponds with the session variable in question? Would that be cleaner and smoother? Thank you.