Sorry for the title but as im pretty worthless at php/mysql i couldnt figure out a good title
I'm currently creating a community for the fun.
I need to be able to get th开发者_运维问答e all of the authed user's info all throughout the site.
Whats the best way to do this? Right now I just have a query in index.php (i include all pages thru index.php) that querys the users table where the id = session[id]. I guess this will really slow down the site as every user keeps reloading pages.
What i wonder is, is there a smarter way?
Get the information when a user first logs in, then keep the data you need in the $_SESSION array.
you can get all vars through the $_SESSION
variable
print_r($_SESSION);
should return the content of the session
It doesn't sound like you should worry much about speed at the moment, querying the database on each request will be fine for now.
Once you get further into your project and maybe all your database queries are starting to slow down your site, THEN you should take a look at optimizations, like reducing the load on the database and caching details.
精彩评论