Ask about general coding issues or problems here.
Moderators: macek, egami, gesf
- New php-forum User
- Posts: 1
- Joined: Tue Nov 13, 2012 7:51 am
I was wanting a way to track if a user was logged in. Each page of the site would validate if the user is logged in or not and would deny access if they are not logged in. This would keep people from going directly to a page on the site without logging in first.
I read up on php sessions, but it was suggested that a database solution might be better. I believe they mean have a field in the user table that denotes if they are logged in or not and then each page validates against that field.
I could set a cookie once they are logged in and then each page could look for that cookie. I am just wondering what solution is generally agreed upon. There are a few different ways to do this, but which one is widely accepted?
- php-forum GURU
- Posts: 2196
- Joined: Wed Oct 06, 2010 11:19 am
- Location: Happy Valley, UT
Sessions are definitely the way to go.
if ($_SESSION['loggedin'] !== TRUE)
die("Sorry, you don't belong here...");
SQL requires a query every time a page is called.. while you may already be calling a load of queries, why put extra stress on your machine when you don't have to.
Return to “PHP coding => General”
Who is online
Users browsing this forum: Yahoo [Bot] and 1 guest