There's nothing fundamentally wrong with it - anything you store in $_SESSION
is, as Barmar already said, reasonable secure. However, using the user's E-Mail as the primary ID internally, and storing the user ID directly in $_SESSION
, is not a great idea architecturally.
The more common approach is to be a bit more abstract: store only a session ID in $_SESSION
.
That ID often points to a "sessions" database table. There is a record for each session in that table, and its status - when it was created, when it's going to time out, whether the user is logged in, etc.
You can theoretically store all this directly in $_SESSION
but then you have no central place where you can see who is currently logged in, which is important for troubleshooting, and log out everyone at once.
That "sessions" table will contain a user ID, which points to a separate "users" table. That ID is ideally a numeric auto-increment value, and the E-Mail is just a column in the users table. That allows relations to other tables to stay intact even when the E-Mail changes. Using the ID, you can get the E-Mail address from that table.
It's more complicated but it saves you a lot of trouble in edge cases, e.g. when a user changes their E-Mail address.