PHP session name

Views: 143 Last modified: July 31st, 2011 Comments: 0

You can specify a default session name in your php.ini file. This is the default name a session is tagged with.
If you want to change this, open your php.ini file and search for the following text:

session.name

Once you found it, you (probably) will notice that this setting has a value: PHPSESSID. This is the default value that comes with PHP. You can change this with anything you want. Be careful, it should only contain alphabetic characters. If there are semicolons in front of it, like this:

;session.name = PHPSESSID

you have to remove the semicolons like this:

session.name = PHPSESSID

Now save your file and restart your server.

However, this is not the only way to do it. You can call and or change the value with PHP like this

// Set new session name
session_name('ContactForm');

// Initialize session
session_start();

Please note that you have to add session_name on each of the pages you want to continue with your defined session_name.
Important: the function session_name() needs to be called before session_start();

You can call the current session name like this:

// Return session name
session_name();

// Echo session_name
echo session_name();
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

    Mail this!

    To: From:Sum {4+7} =  
    Anything to add ?

        You must be logged in to post a comment.