Is it best to store all the users information in session cookies like this on login? Instead of using alot of querys
$_SESSION['id'] = mysql_result($result, 0, 'id');
$_SESSION['name'] = mysql_result($result, 0, 'name');
$_SESSION['email'] = mysql_result($result, 0, 'email');
$_SESSION['ip'] = mysql_result($result, 0, 'regip');
$_SESSION['groupid'] = mysql_result($result, 0, 'group_id');
$_SESSION['style'] = mysql_result($result, 0, 'style');
Or maybe just store ID in session then query on all page:
select * from users where id = $_SESSION['id']
If you’re going to be using them a lot, sure. Although I’d be careful about storing all of the users data in the Session. Only what is necessary. Keep in mind that well-written queries are cheap on resources. Don’t try to avoid connecting to the database altogether, just be sure that when you do it, you do it well.
You can test your memory-consumption if you like using
memory_get_usage(). But note that session data is stored in a flat file on the system itself:So you can see that it’s really very trivial to store this amount of data.
See also: Cache data in PHP SESSION, or query from db each time?