"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.