[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

From session to cookies (PHP)

Posted on 2011-02-19
6
Medium Priority
?
347 Views
Last Modified: 2012-05-11
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
Comment
Question by:GVNPublic123
  • 3
  • 2
6 Comments
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 2000 total points
ID: 34931972
This is good tutorial to use cookie and session, try it
0
 

Author Comment

by:GVNPublic123
ID: 34932002
Also, what values should I use in cookie?

Can I use cookies and session combined?
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 34932018
yes you can very well combine to use cookies and session.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:GVNPublic123
ID: 34932027
What data should I save in cookies?
0
 
LVL 4

Expert Comment

by:LAMASE
ID: 34932241
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
 

Author Comment

by:GVNPublic123
ID: 34932484
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 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