Quick question on session_start()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Reply-Via-Newsgroup Thanks

    Quick question on session_start()


    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
  • Kevin Thorpe

    #2
    Re: Quick question on session_start()

    Reply-Via-Newsgroup Thanks wrote:[color=blue]
    >
    > 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[/color]

    IIRC referring to $_SESSION performs an implicit session_start() . I
    usually put it in there anyway.

    Comment

    • Pedro Graca

      #3
      Re: Quick question on session_start()

      Kevin Thorpe wrote:[color=blue]
      > Reply-Via-Newsgroup Thanks wrote:[color=green]
      >> 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() .[/color][/color]
      [color=blue]
      > IIRC referring to $_SESSION performs an implicit session_start() . I
      > usually put it in there anyway.[/color]

      It depends on session.auto_st art in php.ini

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

      <?php
      if (ini_get('sessi on.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 :

      Comment

      Working...