0
votes

I use a php class for manage session on my own script. in this class i use one static method and on this static method i use session_name("some_name") for rename session default name "PHPSESSID". but when use session_name() function in every reload page session regenerate.

now why regenerate session when use session_name function?


class T_session
{

    // cookie new name
    // expire , path , domain , secure , http only
    static public function set_cookie($cookie_name , $expire = 0 , $path = "/" , $domain = null , $secure = null , $http_only = null ){

        // Set cookie name
        session_name($cookie_name . "_Session");

        // Set the domain to default to the current domain.
                $domain = isset($domain) ? $domain : Tbmedia_domain_root();

        // Set the default secure value to whether the site is being accessed with SSL
            $secure = isset($secure) ? $secure : Tbmedia_check_https();

            session_set_cookie_params($expire,$path,$domain,$secure,true);


            // Configuration php ini
           ini_set('session.save_handler','files');
           ini_set('session.use_cookies',1);
           ini_set('session.cookie_secure',1);
           ini_set('session.use_only_cookies',1);
           ini_set('session.cookie_domain',$domain);
           ini_set('session.cookie_httponly',1);
           ini_set('session.entropy_length',32);
           ini_set('session.entropy_file','/dev/urandom');
           ini_set('session.hash_function','sha256');
           ini_set('session.hash_bits_per_character',5);

           session_start();

    }
   }
bacause the session name defines the session. When it changes the session should be restarted to reflect the new session name. For example using sessions based on cookies. The session name becomes the cookie name. So when changed it is no longer valid and must be regenerated.Nikos M.
it is true , but i use same name in every set_cookie static function in my class. session::set_cookie("Test_name",300); now how can i change session,cookie name without regenerate session?Faramarz Tayyari
you should not do that in main application code but rather through the php settings at the start of each request.php.net/manual/en/session.configuration.phpNikos M.
thanks , i use ini_set('session.name',$cookie_name); but I got the same result. i use ini_set in my class and call set_cookie static function in header off all page. Where should I use ini_set('session.name',$cookie_name) to work properly?Faramarz Tayyari