Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

PHP Session

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

PHP Session

Postby jerim » Tue Nov 13, 2012 8:23 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?
jerim
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Nov 13, 2012 7:51 am

Re: PHP Session

Postby egami » Tue Nov 13, 2012 8:27 am

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.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to PHP coding => General

Who is online

Users browsing this forum: Exabot [Bot] and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron