?
Solved

php convert cookie to session

Posted on 2006-11-25
5
Medium Priority
?
474 Views
Last Modified: 2012-05-05
I have a website that uses php cookies.
Is there an easy way to convert it to session variables?

What would I need to do?

Also, is there anything I should watch out for?
0
Comment
Question by:jackjohnson44
[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
5 Comments
 
LVL 29

Expert Comment

by:TeRReF
ID: 18012399
foreach($_COOKIE as $key=>$value) {
    $_SESSION[$key] = $value;
}

I don't think you need to watch out for anything, sessions are safer then cookies anyway...
0
 

Author Comment

by:jackjohnson44
ID: 18012538
do I have to put anything else in my script? start the session

Also will a session persist across a move from the http side to https side of the domain?
0
 
LVL 29

Accepted Solution

by:
TeRReF earned 1200 total points
ID: 18012703
> do I have to put anything else in my script? start the session
Use
session_start();
at the beginning of your php page to start the session

> Also will a session persist across a move from the http side to https side of the domain?
Yes, that shouldn't be a problem.
0
 
LVL 8

Assisted Solution

by:John Kawakami
John Kawakami earned 400 total points
ID: 18012881
Just to add on TeRReF's comment - sessions are implemented with cookies.  The session data is written to a file, and the name of that file is stored in a browser cookie named PHPSESSID.
0
 
LVL 1

Assisted Solution

by:bobbyo
bobbyo earned 400 total points
ID: 18044558
One thing to add. There is a setting in the php.ini file that will start sessions automatically

session.auto_start = 1

As for session value been stored in the cookie. This can also be enabled or disabled in the php.ini file

session.use_cookies = 1

If it is set to 0 the session variable normally PHPSESSID is maintained via the url. If you use normal href tags or forms the id should be maintained automatically in the url however if you use javascript redirects it will be lost.
0

Featured Post

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!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

719 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