views:

37

answers:

4

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.

+1  A: 

$_SESSION is a global.

Start it off by calling session_start() before any output.

alex
Thanks For the Answers, but my problem is, when i start the session on my first page, i cant access the session values on the other pages. To be more specific when i debug using eclipse, i can see the session started in the first page and it gets resetted to empty when i use header(..); on my page to forward to other pages. I dont why it is resetted, when i am not calling session_destroy();
tsegay
@tsegay You should put you session_start() on all pages where you intend to use sessions.
Centurion
A: 
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");

Chris
A: 

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.

Wrikken
Thanks For the Answers, but my problem is, when i start the session on my first page, i cant access the session values on the other pages. To be more specific when i debug using eclipse, i can see the session started in the first page and it gets resetted to empty when i use header(..); on my page to forward to other pages.I dont why it is resetted, when i am not calling session_destroy();
tsegay
A: 

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.

Col. Shrapnel