How can i start a session in PHP which will be global to all my pages. I don't have access to the php.ini
file. So session.auto_start = 0
in my php.ini
will not be a solution for me.
Thanks.
How can i start a session in PHP which will be global to all my pages. I don't have access to the php.ini
file. So session.auto_start = 0
in my php.ini
will not be a solution for me.
Thanks.
$_SESSION
is a global.
Start it off by calling session_start()
before any output.
session_start();
Place this at the top of your pages and it will start a session. You can access it and set its variables with $_SESSION['somevalue']. Also you can name the session using session_name("some name");
If you want all pages to automagically have a session_start()
, without actually writing the code, you're pretty much stuck with ini-settings. It is very well possible that although you cannot alter php.ini
in a shared environment (proper hosters do offer a custom ini IMO), that you can just add the php_flag session.autostart = 1
to an .htaccess file in the root.
Nothing bad in starting a session with session_start() - everyone doing that.
Don't you have some config file already, which being included into every script on the site? If yes - why not to put session_start there? If not - you have to think of having one.