By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,350 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,350 IT Pros & Developers. It's quick & easy.

$_SESSION, autostart

P: n/a
I just started with a service provider who's giving me a server to put
my scripts. I noticed when I copy scripts that work on my machine to
this server, all things $_SESSION are null. I read some on php.net and
found that session_autostart has to be set to true in order for me to
use $_SESSION variables at all. Am I reading that right? Obviously, I
have no control over this setting on someone else's server so I cannot
change it. Is this why my $_SESSION values are all null? Is there a
workaround? I tried putting session_start(); at the very beginning of
the first script. No change.

Thanks in advance,
Jeff Sandler
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Jeff Sandler" wrote
I read some on php.net and found that session_autostart has to
be set to true in order for me to use $_SESSION variables at all.
Am I reading that right?
No, read on. If you still know where you've read that then please anotate
that very page with whatever you're learning here...
Obviously, I have no control over this setting on someone
else's server so I cannot change it.
This is your lucky day ;-) Note that http://php.net/session states
PHP_INI_ALL for this option, so you can also override in the PHP script
itself (well, that could hardly be called "auto start" then; use
session_start() instead) or when using Apache you can enable it in a
..htaccess file in your script's directory, or even in your own root
directory. See http://php.net/ini-set and
http://php.net/configuration.changes

Note that the correct full name is

session.auto_start

so for Apache you'd use

php_flag session.auto_start on

Note that using session.auto_start is not always a good choice: you cannot
put any objects in your session... Again, read http://php.net/session or
read on to use session_start()...
I tried putting session_start(); at the very beginning of
the first script. No change.


When not using the auto start setting, you need the session_start() in every
script that is invoked by your visitor (as in: every page, even if it is not
using any session data, in order to keep the session alive when the visitor
is not accepting cookies), not just in the first one.

In general, you'll see if sessions are working if PHP is trying to set a
cookie. Type

javascript:alert(document.cookie);

in the Location / URL / Address field of your browser to see if any cookie
is set. Furthermore, on the very first page that you started the session on,
you *might* find that all relative URLs have a PHPSESSID GET parameter
appended to them (depends on your settings).

Adriaan.
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.