[Last Call] Learn how to a build a cloud-first strategyRegister Now


php: Cookies: is it save for the cookie name to be the same as the session ID?

Posted on 2011-10-05
Medium Priority
Last Modified: 2012-08-13
Hello Experts,

is it save for the cookie name to be the same as the session ID?
if not, why not?

Question by:epifanio67
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36923262
Because it is just plain confusing.  Why would you want to do that?  Every time you go to a site, you get a different 'session_id' so you would have a bunch of cookies with 'session_id's for names.
LVL 111

Accepted Solution

Ray Paseur earned 2000 total points
ID: 36923771
$_COOKIE is an array.  The names of the cookies are keys that point to values.  The names and values are created on the server by your programming, sent to the client browser with the setcookie() function, stored on the browser and returned to the server on subsequent HTTP requests, where they are preloaded into $_COOKIE for use by your PHP script.  Thus the server has taken the "stateless" http protocol and introduced a way of understanding and controlling the browser's state.

The usual name of a PHP session cookie is PHPSESSID.  You can change that. The usual value is something that looks like the md5() string, for example, 3b63f439eb5a296257f513b32348053b.  So if I understand your question correctly, you want to set a cookie with the name 3b63f439eb5a296257f513b32348053b.  As a professional programmer I think you might want to choose meaningful names for variables and keys.

I view this question like "Is it safe to give my my dog and my daughter the same name?"  You might be able to live with the consequences of a decision like that, or you might find that things did not work out very well.  Only time will tell.  In our household, we think of Bowser and Jennifer in different terms.

Author Closing Comment

ID: 36925610
great answer.. thank you expert..
really helped

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
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
Course of the Month18 days, 4 hours left to enroll

830 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