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

Quick question on session_start()

P: n/a

Folks,

I consider myself a reasonably strong PHP programmer, but I've not used
sessions before (I've used cookies instead) and I'd appreciate it if
someone could confirm something for me.

Namely... I'm working on someone else's code who has used sessions - In
their main login page, they do not use session_start() but instead, just
write directly to the $_SESSION super global array variable. This seems
to work - however on some later pages, he has session_start() noted at
the top of his code - I've read some of the documentation on sessions
and I believe that since I am using Apache 1.3.29 with PHP 4.3.6 that it
may not be nescessary to have the session_start().

A quote from the php.net documentation says:

"Note: As of PHP 4.3.3, calling session_start() while the session has
already been started will result in an error of level E_NOTICE. Also,
the second session start will simply be ignored."

Thus, can one start a session by simply writing to the $_SESSION super
global array and forget about every using session_start() ????

Help via the newsgroup (so everyone can learn) would be much
appreciated, thanks

randelld
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Reply-Via-Newsgroup Thanks wrote:

Folks,

I consider myself a reasonably strong PHP programmer, but I've not used
sessions before (I've used cookies instead) and I'd appreciate it if
someone could confirm something for me.

Namely... I'm working on someone else's code who has used sessions - In
their main login page, they do not use session_start() but instead, just
write directly to the $_SESSION super global array variable. This seems
to work - however on some later pages, he has session_start() noted at
the top of his code - I've read some of the documentation on sessions
and I believe that since I am using Apache 1.3.29 with PHP 4.3.6 that it
may not be nescessary to have the session_start().

A quote from the php.net documentation says:

"Note: As of PHP 4.3.3, calling session_start() while the session has
already been started will result in an error of level E_NOTICE. Also,
the second session start will simply be ignored."

Thus, can one start a session by simply writing to the $_SESSION super
global array and forget about every using session_start() ????

Help via the newsgroup (so everyone can learn) would be much
appreciated, thanks


IIRC referring to $_SESSION performs an implicit session_start(). I
usually put it in there anyway.
Jul 17 '05 #2

P: n/a
Kevin Thorpe wrote:
Reply-Via-Newsgroup Thanks wrote:
Namely... I'm working on someone else's code who has used sessions - In
their main login page, they do not use session_start() but instead, just
write directly to the $_SESSION super global array variable. This seems
to work - however on some later pages, he has session_start() noted at
the top of his code - I've read some of the documentation on sessions
and I believe that since I am using Apache 1.3.29 with PHP 4.3.6 that it
may not be nescessary to have the session_start().
IIRC referring to $_SESSION performs an implicit session_start(). I
usually put it in there anyway.


It depends on session.auto_start in php.ini

You can check it if your script might be running in several different
servers with different configurations:

<?php
if (ini_get('session.auto_start') != '1') session_start();
?>
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.