[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

From session to cookies (PHP)

Posted on 2011-02-19
6
Medium Priority
?
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

649 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