What role does session.autostart play in PHP sessions and potential pitfalls?

Setting session.autostart to true in PHP will automatically start a session on every page load, which can lead to unnecessary session creation and potential performance issues. To solve this, you can manually start the session only when needed by setting session.autostart to false and calling session_start() in your code when necessary.

// Disable session autostart
ini_set('session.autostart', 0);

// Start session only when needed
session_start();