/    Sign up×
Community /Pin to ProfileBookmark

PHP pdo login

Hi guys. I’m putting together an online workout planner just for me to keep track of my workout progress. It will only have like 5 pages. The first page being the login page. What I’m wondering is what is the most efficient way to ensure that a user can only view the pages within the site if he/she is logged in.

Not looking for code examples just the basic logic.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@deepgauravMay 18.2019 — @coleio#1603806

Hi, SESSIONS are generally used for that, start session on login and end in logout, in other pages, check if SESSION is started if so display page accordingly otherwise redirect to login page.
Copy linkTweet thisAlerts:
@coleioauthorMay 18.2019 — so use the session to store the username and password?
Copy linkTweet thisAlerts:
@ginerjmMay 18.2019 — NO - you store the id and pswd in your db table. When you get a signin you check the db and if it was valid, you save a token in the session, or even as a cookie. NEVER save a pswd outside of the db table. And be sure to define a properly sized column for it that allows for the length of the encryption that you use!

As for the token - it can be the userid or it can be a value that represents the type of access granted. Depends upon on how it will be used later on in your app.
Copy linkTweet thisAlerts:
@coleioauthorMay 18.2019 — So the user id is stored as a session variable?
Copy linkTweet thisAlerts:
@ginerjmMay 18.2019 — Whatever you think is best for you to store in the SESSION variable. It depends on your appl. design
×

Success!

Help @coleio spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...