• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

From session to cookies (PHP)

Hello.

My site is entirely session based (you login, and than session is started and some session variables are generated needed for all to work (like $_SESSION['username']).

I would like to upgrade to cookies, where user would be able to login for either cookie that expires when browser is closed either cookie that is stored for a month or something.

What would be easiest and best way to upgrade, any tips?
0
GVNPublic123
Asked:
GVNPublic123
  • 3
  • 2
1 Solution
 
Loganathan NatarajanLAMP DeveloperCommented:
This is good tutorial to use cookie and session, try it
0
 
GVNPublic123Author Commented:
Also, what values should I use in cookie?

Can I use cookies and session combined?
0
 
Loganathan NatarajanLAMP DeveloperCommented:
yes you can very well combine to use cookies and session.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
GVNPublic123Author Commented:
What data should I save in cookies?
0
 
LAMASECommented:
I suggest to save the session data in a db, because cookie are plain text and can be stolen/read easily. In addition, the cookie data is passed for EVERY REQUEST (images too) to your server, and with a lot of data this is not a good practice.

I suggest to save the data in a db associated with the session_id, and then manipulate the lifetime of the session cookie (just re-set with the same name, content etc with a modified end-date)
http://php.net/manual/en/function.setcookie.php
0
 
GVNPublic123Author Commented:
Ok,

My cookies (2) are:
- username
- sha1 combination of some user's data (including salt)

All my members area sites require session data, therefore first its checked that user is logged in and has session data, if not cookie is checked and validated, session data created, cookie extended for 7 days.

Login has option of either session or cookies.
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now