PHP Session name


Example

Checking if session cookies have been created

Session name is the name of the cookie used to store sessions. You can use this to detect if cookies for a session have been created for the user:

if(isset($_COOKIE[session_name()])) {
    session_start();
}

Note that this method is generally not useful unless you really don't want to create cookies unnecessarily.

Changing session name

You can update the session name by calling session_name().

//Set the session name
session_name('newname');
//Start the session
session_start();

If no argument is provided into session_name() then the current session name is returned.

It should contain only alphanumeric characters; it should be short and descriptive (i.e. for users with enabled cookie warnings). The session name can't consist of digits only, at least one letter must be present. Otherwise a new session id is generated every time.