I have a login-system. When a user logs in the user data get stored in $_SESSION variables (id, username,...) like this (login.php):
$sql = 'SELECT * FROM users WHERE username = :username';
$statement = $con->prepare($sql);
$result = $statement->execute(array('username' => $username));
$userdata = $statement->fetch();
$hashedPassword = json_encode($userdata['password']);
//check password
if ($result && password_verify($password, $userdata['password'])) {
session_regenerate_id();
$_SESSION['loggedIn'] = true;
$_SESSION['username'] = $username;
$_SESSION['id'] = $userdata['id'];
echo $_SESSION['id'];
echo 'true';
} else {
exit('false');
}
}else{
exit('false');
}
Now my question: Is it a security problem, when I use this data as trustworthy data, maybe like:
INSERT INTO userRelatedTable (userId,data1,data2) VALUES ($_SESSION['userid'] (<= !!!) ,'data1','data2')
In other words: Does php handle the security part when i say session_start(); with a sessionkey, or do i have to generate a key, store it and use it as an identifier by myself?
Greetings