Solved

From session to cookies (PHP)

Posted on 2011-02-19
6
277 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 500 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now