473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

So what happens after creating the login mechanism?

pek
I have read a lot of tutorials on how to create a login mechanism (a
lot of which I found really useful). None of them however explain how
do you check if the user is or is not in fact logged in.

What is your implementation? What do you believe is a good practice
and what is not? Do you provide both sessions and cookies for temporal
and long-term logins..?
Jun 27 '08 #1
6 1663
pek wrote:
I have read a lot of tutorials on how to create a login mechanism (a
lot of which I found really useful). None of them however explain how
do you check if the user is or is not in fact logged in.

What is your implementation? What do you believe is a good practice
and what is not? Do you provide both sessions and cookies for temporal
and long-term logins..?
That is because HTTP itself is a stateless protocol.

Each page resquest is an atomic session: you can have no idea at the
server end whether the request is from someone who has been staring at
the screen with your site displayed on it for a week, or has in fact
been on holiday in outer mongolia.

Hence the use of sessions, where cookies are used to carry state
information,stored in the browser,between page requests.

So in terms of whether a user is loggen in or not on THAT basis, if he
connects with a valid name/password cobo,he is loggen in until you
decide he isn;t.

If on the other hand you want to detect who is actually requesting a
page, the web logs generally tell you that if you use ,htXXXX type
access mechanism,and IIRC the login info is carried in a PHP global
varaiable somewhere. Can't remember.If you use sessions its caried in e
session info.

Jun 27 '08 #2
pek
On Jun 25, 5:07*pm, The Natural Philosopher <a...@b.cwrote:
pek wrote:
I have read a lot of tutorials on how to create a login mechanism (a
lot of which I found really useful). None of them however explain how
do you check if the user is or is not in fact logged in.
What is your implementation? What do you believe is a good practice
and what is not? Do you provide both sessions and cookies for temporal
and long-term logins..?

That is because HTTP itself is a stateless protocol.

Each page resquest is an atomic session: you can have no idea at the
server end whether the request is from someone who has been staring at
the screen with your site displayed on it for a week, or has in fact
been on holiday in outer mongolia.

Hence the use of sessions, where cookies are used to carry state
information,stored in the browser,between page requests.

So in terms of whether a user is loggen in or not on THAT basis, if he
connects with a valid name/password cobo,he is loggen in until you
decide he isn;t.

If on the other hand you want to detect who is actually requesting a
page, the web logs generally tell you that if you use ,htXXXX type
access mechanism,and IIRC the login info is carried in a PHP global
varaiable somewhere. Can't remember.If you use sessions its caried in e
session info.
Yes, I kinda know all this. My question was what is your actual code
that looks if a user is logged in or not?
Is it something likes this:

if ( isset($_SESSION['user'])) {
// he is logged in
} else {
// redirect to login
}

Or is it more advanced?

What is your code of checking..?
Jun 27 '08 #3
On Jun 25, 1:52 pm, pek <kimwl...@gmail.comwrote:
I have read a lot of tutorials on how to create a login mechanism (a
lot of which I found really useful). None of them however explain how
do you check if the user is or is not in fact logged in.

What is your implementation? What do you believe is a good practice
and what is not? Do you provide both sessions and cookies for temporal
and long-term logins..?
You're confusing authentication and session management. If you try to
make them the same thing, and you allow users to login without
expiring for a long period of time you will have to maintain the user
session for that time - which is not going to scale well nor allow for
change management.

By all means allow your website to 'remember me' - but implement this
seperately from the session handling.

Then do authentication for any users who does not have a valid
session, if the user is authenticated, create a session or flag the
session as valid.

C.

Jun 27 '08 #4
pek
On Jun 26, 3:42 pm, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.comwrote:
On Jun 25, 1:52 pm, pek <kimwl...@gmail.comwrote:
I have read a lot of tutorials on how to create a login mechanism (a
lot of which I found really useful). None of them however explain how
do you check if the user is or is not in fact logged in.
What is your implementation? What do you believe is a good practice
and what is not? Do you provide both sessions and cookies for temporal
and long-term logins..?

You're confusing authentication and session management. If you try to
make them the same thing, and you allow users to login without
expiring for a long period of time you will have to maintain the user
session for that time - which is not going to scale well nor allow for
change management.

By all means allow your website to 'remember me' - but implement this
seperately from the session handling.

Then do authentication for any users who does not have a valid
session, if the user is authenticated, create a session or flag the
session as valid.

C.
OK, maybe I didn't make myself clear.

My question is simply this:
What is your code to check wether a user is logged in or not.
Jun 27 '08 #5
pek schreef:
On Jun 26, 3:42 pm, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.comwrote:
>On Jun 25, 1:52 pm, pek <kimwl...@gmail.comwrote:
>>I have read a lot of tutorials on how to create a login mechanism (a
lot of which I found really useful). None of them however explain how
do you check if the user is or is not in fact logged in.
What is your implementation? What do you believe is a good practice
and what is not? Do you provide both sessions and cookies for temporal
and long-term logins..?
You're confusing authentication and session management. If you try to
make them the same thing, and you allow users to login without
expiring for a long period of time you will have to maintain the user
session for that time - which is not going to scale well nor allow for
change management.

By all means allow your website to 'remember me' - but implement this
seperately from the session handling.

Then do authentication for any users who does not have a valid
session, if the user is authenticated, create a session or flag the
session as valid.

C.

OK, maybe I didn't make myself clear.

My question is simply this:
What is your code to check wether a user is logged in or not.
Hi,

You cannot expect us to give you litteral code.
YOU are the one designing the authentication and the subsequent checking.

A simple example:
login.php
contains a form where a username and password is typed.
It posts to:

login_process.php
Here you check the passed username/password against a database or
something that holds this information.
if succesfull:

So you'll end up with something like:
[just a codesinppet]
session_start();
$username = $connection->qstr($_POST["username"]);
$password = $connection->qstr($_POST["password"]);
// The $connection->qstr is from ADODB db abstractionlayer.
// You might well use another to prevent SQL injection.
$SQL = "SELECT userid FROM tbluser WHERE ((username=$username) AND
(password=$password));"
$RS = $connection->getAll($SQL);
if (isset($RS[0])){
// OK
$_SESSION["userid"] = $rowDB["userid"];
header("Location: userpage.php");
exit;
} else {
echo "bad username and password. Try again.";
exit;
}

userpage.php
On this page you damnd a logged in user, so start this page with:
session_start();
if (!isset($_SESSION["userid"])){
echo "Sorry, your session expired, or you are screwing up somehow.";
exit;
}
Since you'll end up with the above checkroutine on every page, I advise
you to put the whole into a function, named eg: redirectIfNotLoggedIn().

Hope this helps a little.

So in short: You make some entry in $_SESSION on succesfull login, and
you check it everywhere where you demand a logged in user.

Regards,
Erwin Moller
Jun 27 '08 #6
On Wed, 25 Jun 2008 14:38:15 -0700 (PDT), pek wrote:
Yes, I kinda know all this. My question was what is your actual code
that looks if a user is logged in or not?
Is it something likes this:

if ( isset($_SESSION['user'])) {
// he is logged in
} else {
// redirect to login
}

Or is it more advanced?
That's usually sufficient for casual "logged in" checking. I'd work
harder for financial information, but for a "is this user allowed to
comment on these pictures" kind of thing? It's probably all you need.

--
With a Dremel tool and a cut-off wheel, _everything_ takes a flat-blade
screwdriver.
-- Matt Roberds in the Monastery
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: 127.0.0.1 | last post by:
Within the bounds of Javascript and pHP, what is the securest login mechanism anyone here has come up with. -- Spam:newsgroup(at)craznar.com@verisign-sux-klj.com...
7
by: Angelos | last post by:
Any Suggestions for an Authentication System ... Do you have any Links to suggest ? My current Authentication works ok but it has a major BUG !!! BUG: If I use the same Authentication mechanism...
3
by: dnagel | last post by:
I have a session timing out after 10 minutes. If the user clicks a submit button to post some form data after the timeout has expired, they are redirected to a login page... Whats the standard...
13
by: Crouchie1998 | last post by:
What's the simplest way to create a login page in ASP.NET & VB.NET? Awaiting your reply, Crouchie1998 BA (HONS) MCP MCSE
9
by: dana lees | last post by:
Hello, I am developing a C# asp.net application. I am using the authentication and authorization mechanism, which its timeout is set to 60 minutes. My application consists of 2 frames - a...
8
by: PW | last post by:
I've added a punlic domain security login page to one of my web applications. I did this because the number of users has increased to a couple of dozen, and having them all added as users on my...
5
by: djhexx | last post by:
Hi. We have an asp.net intranet application written in VB that uses forms authentication for all it's pages. I have a C# asp.net application that I just wrote. The company would like the C#...
2
by: astolpho | last post by:
I am using a slightly outdated reference book on J2EE programming. It gives 2 methods of creating a database used in its casestudies. The first is an ANT script that gives the following output: ...
3
by: chris fellows | last post by:
I am writing a generic login mechanism for our web apps using ASP.NET / C# (VS2005). Various web pages need to present a login dialogue for the user to re-enter their application-level username &...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.