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

Posted on 2011-10-05
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 82

    Expert Comment

    by:Dave Baldwin
    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 107

    Accepted Solution

    $_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

    great answer.. thank you expert..
    really helped

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    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 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 …

    729 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

    15 Experts available now in Live!

    Get 1:1 Help Now