Here, I come with the quick and simple article.Session in PHP gives you the ability to record any number of variables and store them in between the execution of the request. You all know about the session and if you want to use session in PHP, you need to explicitly start or resume that session by using session function in PHP and you need to call the session_start() function for each PHP script.
After a session is started, you will have access of the session ID by the session_id() function in PHP. The session_id() function allows you to either set or retrieve a session ID.Automatically starting session in PHP So, You don’t need to start session explicitly through session_start ()
Sessions remain same as long as the web browser is active. When the user restarts the browser, the cookie is destroyed from the browser. You can change this by setting session.cookie_lifetime in your php.ini file. The default value is 0 and you can set an expiry period in seconds.
1) PHP.INI METHOD
If you want to start a session automatically, you will have to find the below line in your php.ini file and change the value from 0 to 1 and restart your server.
Here is the example to set the value of auto_start using configuration file in PHP.
session.auto_start = 0
By replacing or adding the value of session.auto_start to 1, you can check that a session is initiated for every PHP files.
2) .HTACCESS METHOD
Now if you don’t have an access to your php.ini file so you can auto start a session from the .htaccess file as well. just place the following line of code in your .htaccess file.
php_value session.auto_start 1
You may also like: