Solved

Is it necessary to set a session and cookie for user login?

Posted on 2016-10-04
3
49 Views
Last Modified: 2016-10-04
Currently, I have my code in such a way that if a user logs in without choosing "remember me", a session is set when they login. If they choose "remember me", I set only a cookie and no session. Is this acceptable or should you set a session as well? I am not sure what the common practice is.
0
Comment
Question by:Black Sulfur
3 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 41828537
Sessions normally set a cookie of their own.  I just use sessions for login.  "remember me" is usually for an 'automatic' login at a later date.  That would require a cookie because sessions don't last that long.
0
 

Author Comment

by:Black Sulfur
ID: 41828579
Thanks, Dave. So what I am doing is fine then? If they check the "remember me" checkbox  I then just set a cookie with an expiry date and don't set a session using $_SESSION['session_name'] like I would if they don't check "remember me".
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 41828581
You should probably set a session as well.  This article shows the time-honored traditional solutions.  You can copy the code samples and use them, or just follow the logic and general guidance.
https://www.experts-exchange.com/articles/2391/PHP-Client-Registration-Login-Logout-and-Easy-Access-Control.html
1

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question