Problem with SESSION variables...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ZoombyWoof

    Problem with SESSION variables...

    Hi. Im very new to php, and I have a problem here that I cant find the
    solution for. I have problems with session variables, I want some
    variables to maintain their value between different php script that is
    being called. I have read the online manual, and here is an example from
    it that doesnt work for me, it illustrates very well my problem.

    File 1, index.php

    <?php
    // index.php

    session_start() ;

    echo '<br />Welcome to page #1';

    $_SESSION['favcolor'] = 'green';
    $_SESSION['animal'] = 'cat';
    $_SESSION['time'] = time();


    // Works if session cookie was accepted
    echo '<br /><a href="page2.php ">page 2</a>';

    // Or maybe pass along the session id, if needed
    echo '<br /><a href="page2.php ?' . SID . '">page 2</a>';
    ?>

    File 2, page2.php

    <?php
    // page2.php

    session_start() ;

    echo '<br />Welcome to page #2<br />';

    echo $_SESSION['favcolor']; // green
    echo $_SESSION['animal']; // cat
    echo date('Y m d H:i:s', $_SESSION['time']);

    // You may want to use SID here, like we did in page1.php
    echo '<br /><a href="index.php ">page 1</a>';
    ?>

    I get no output, except the date which shows 1970 bla bla

    I have apache 2.0.48, PHP 4.3.3 running on a Redhat 9.0 box. I have not
    touched the register_global s in php.ini, it's Off. What can be the problem
    here ? Any help would be much appreciated, I'm stuck....

    Thanx

    /ZoombyWoof

  • Pedro

    #2
    Re: Problem with SESSION variables...

    ZoombyWoof wrote:
    [...][color=blue]
    > I get no output, except the date which shows 1970 bla bla
    >
    > I have apache 2.0.48, PHP 4.3.3 running on a Redhat 9.0 box. I have not
    > touched the register_global s in php.ini, it's Off. What can be the problem
    > here ? Any help would be much appreciated, I'm stuck....[/color]

    What do you have for "session.save_p ath" in php.ini?
    Does the webserver have write-access to that directory?

    --
    I have a spam filter working.
    To mail me include "urkxvq" (with or without the quotes)
    in the subject line, or your mail will be ruthlessly discarded.

    Comment

    • ZoombyWoof

      #3
      Re: Problem with SESSION variables...

      On Tue, 04 Nov 2003 15:32:14 +0000, Pedro wrote:
      [color=blue]
      > ZoombyWoof wrote:
      > [...][color=green]
      >> I get no output, except the date which shows 1970 bla bla
      >>
      >> I have apache 2.0.48, PHP 4.3.3 running on a Redhat 9.0 box. I have not
      >> touched the register_global s in php.ini, it's Off. What can be the problem
      >> here ? Any help would be much appreciated, I'm stuck....[/color]
      >
      > What do you have for "session.save_p ath" in php.ini?
      > Does the webserver have write- permissions are[/color]
      rwxrwxrwxt owned by root, so that shouldnt be a problem, or ?

      /ZW

      Comment

      • Jon Kraft

        #4
        Re: Problem with SESSION variables...

        ZoombyWoof <zoombywoofremo ve@thishotmail. com> wrote:
        [color=blue]
        > Hi. Im very new to php, and I have a problem here that I cant find the
        > solution for. I have problems with session variables, I want some
        > variables to maintain their value between different php script that is
        > being called. I have read the online manual, and here is an example from
        > it that doesnt work for me, it illustrates very well my problem.
        >
        > // Or maybe pass along the session id, if needed
        > echo '<br /><a href="page2.php ?' . SID . '">page 2</a>';[/color]

        The above will only work if you set session.use_tra ns_sid in php.ini to 1.
        Furthermore cookies must be accepted by your browser in order to work.

        Alternatively you could use:

        echo '<br /><a href="page2.php ?'.session_name ().'='.session_ id().'">page
        2</a>';

        Check the session cookie on page 2 with session_get_coo kie_params() .. if
        that's empty, the cookie hasn't been set.



        HTH;
        JOn

        --
        Begathon, n.:
        A multi-day event on public television, used to raise money so
        you won't have to watch commercials.

        Comment

        • ZoombyWoof

          #5
          Re: Problem with SESSION variables...

          On Tue, 04 Nov 2003 15:35:08 +0000, Jon Kraft wrote:
          [color=blue]
          > ZoombyWoof <zoombywoofremo ve@thishotmail. com> wrote:
          >[color=green]
          >> Hi. Im very new to php, and I have a problem here that I cant find the
          >> solution for. I have problems with session variables, I want some
          >> variables to maintain their value between different php script that is
          >> being called. I have read the online manual, and here is an example from
          >> it that doesnt work for me, it illustrates very well my problem.
          >>
          >> // Or maybe pass along the session id, if needed
          >> echo '<br /><a href="page2.php ?' . SID . '">page 2</a>';[/color]
          >
          > The above will only work if you set session.use_tra ns_sid in php.ini to 1.
          > Furthermore cookies must be accepted by your browser in order to work.
          >
          > Alternatively you could use:
          >
          > echo '<br /><a href="page2.php ?'.session_name ().'='.session_ id().'">page
          > 2</a>';
          >
          > Check the session cookie on page 2 with session_get_coo kie_params() .. if
          > that's empty, the cookie hasn't been set.
          >
          > http://uk.php.net/manual/en/function...kie-params.php
          >
          > HTH;
          > JOn[/color]
          I have tried all of what you suggested above, setting use_trans_sid to 1
          didnt help. I used the link with session_name=se ssion_id, didnt help. I
          have changed session.save_pa th to /usr/local/apache2/sessions, apache owns
          that directory, apache is the user who runs the server, but nothing goes
          in that directory. I have checked the cookie_params, and it doesnt contain
          anything else from what is set as default in php.ini.
          I dont understand this....*HELP* :-)

          Thanx

          /ZW

          Comment

          • Jon Kraft

            #6
            Re: Problem with SESSION variables...

            ZoombyWoof <zoombywoofremo ve@thishotmail. com> wrote:
            [color=blue]
            > I have tried all of what you suggested above, setting use_trans_sid to 1
            > didnt help. I used the link with session_name=se ssion_id, didnt help. I
            > have changed session.save_pa th to /usr/local/apache2/sessions, apache owns
            > that directory, apache is the user who runs the server, but nothing goes
            > in that directory. I have checked the cookie_params, and it doesnt contain
            > anything else from what is set as default in php.ini.
            > I dont understand this....*HELP* :-)[/color]

            Hm, strange, are you sure you are editing the php.ini PHP uses? Check with
            phpinfo(). That will also tell you whether PHP was compiled with
            --disable-session.

            JOn

            --
            He only knew his iron spine held up the sky -- he didn't realize his brain
            had fallen to the ground.
            -- The Book of Serenity

            Comment

            • ZoombyWoof

              #7
              Re: Problem with SESSION variables...

              On Tue, 04 Nov 2003 18:15:12 +0000, Jon Kraft wrote:
              [color=blue]
              > ZoombyWoof <zoombywoofremo ve@thishotmail. com> wrote:
              >[color=green]
              >> I have tried all of what you suggested above, setting use_trans_sid to 1
              >> didnt help. I used the link with session_name=se ssion_id, didnt help. I
              >> have changed session.save_pa th to /usr/local/apache2/sessions, apache owns
              >> that directory, apache is the user who runs the server, but nothing goes
              >> in that directory. I have checked the cookie_params, and it doesnt contain
              >> anything else from what is set as default in php.ini.
              >> I dont understand this....*HELP* :-)[/color]
              >
              > Hm, strange, are you sure you are editing the php.ini PHP uses? Check with
              > phpinfo(). That will also tell you whether PHP was compiled with
              > --disable-session.
              >
              > JOn[/color]
              Yes, I'm editing the one PHP is using, it's /etc/php.ini, however, if you
              mean that it should say --disable-session under configure command at the
              top, it doesnt. Do I have to have disable-session compiled in ? Why is
              this not the default, if it's necessary to get session to work...?

              Thanx

              /ZW

              Comment

              • Justin Koivisto

                #8
                Re: Problem with SESSION variables...

                ZoombyWoof wrote:
                [color=blue]
                > On Tue, 04 Nov 2003 15:35:08 +0000, Jon Kraft wrote:
                >
                >[color=green]
                >>ZoombyWoof <zoombywoofremo ve@thishotmail. com> wrote:
                >>
                >>[color=darkred]
                >>>Hi. Im very new to php, and I have a problem here that I cant find the
                >>>solution for. I have problems with session variables, I want some
                >>>variables to maintain their value between different php script that is
                >>>being called. I have read the online manual, and here is an example from
                >>>it that doesnt work for me, it illustrates very well my problem.
                >>>
                >>>// Or maybe pass along the session id, if needed
                >>>echo '<br /><a href="page2.php ?' . SID . '">page 2</a>';[/color]
                >>
                >>The above will only work if you set session.use_tra ns_sid in php.ini to 1.
                >>Furthermore cookies must be accepted by your browser in order to work.
                >>
                >>Alternative ly you could use:
                >>
                >>echo '<br /><a href="page2.php ?'.session_name ().'='.session_ id().'">page
                >>2</a>';
                >>
                >>Check the session cookie on page 2 with session_get_coo kie_params() .. if
                >>that's empty, the cookie hasn't been set.
                >>
                >>http://uk.php.net/manual/en/function...kie-params.php
                >>
                >>HTH;
                >>JOn[/color]
                >
                > I have tried all of what you suggested above, setting use_trans_sid to 1
                > didnt help.[/color]

                Did you restart the webserver after editing php.ini? That's a commonly
                overlooked step...
                [color=blue]
                > I used the link with session_name=se ssion_id, didnt help. I
                > have changed session.save_pa th to /usr/local/apache2/sessions, apache owns
                > that directory, apache is the user who runs the server, but nothing goes
                > in that directory. I have checked the cookie_params, and it doesnt contain
                > anything else from what is set as default in php.ini.[/color]

                Be sure that session.auto_st art is off.

                session.save_ha ndler needs to be set to files for session.save_pa th to
                be used.

                session.use_coo kies should be on if you want to use cookies. If you want
                to use *only* cookies, then session.use_onl y_cookies should be on as well.

                Make sure that session.gc_maxl ifetime isn't set really low (default is
                1440 seconds, or 24 minutes). Same with session.cookie_ lifetime, but 0
                is no exipre in this case. (Watch for session.cache_e xpire as well.)

                --
                Justin Koivisto - spam@koivi.com
                PHP POSTERS: Please use comp.lang.php for PHP related questions,
                alt.php* groups are not recommended.

                Comment

                • Justin Koivisto

                  #9
                  Re: Problem with SESSION variables...

                  ZoombyWoof wrote:
                  [color=blue]
                  > On Tue, 04 Nov 2003 18:15:12 +0000, Jon Kraft wrote:
                  >[color=green]
                  >>ZoombyWoof <zoombywoofremo ve@thishotmail. com> wrote:
                  >>[color=darkred]
                  >>>I have tried all of what you suggested above, setting use_trans_sid to 1
                  >>>didnt help. I used the link with session_name=se ssion_id, didnt help. I
                  >>>have changed session.save_pa th to /usr/local/apache2/sessions, apache owns
                  >>>that directory, apache is the user who runs the server, but nothing goes
                  >>>in that directory. I have checked the cookie_params, and it doesnt contain
                  >>>anything else from what is set as default in php.ini.
                  >>>I dont understand this....*HELP* :-)[/color]
                  >>
                  >>Hm, strange, are you sure you are editing the php.ini PHP uses? Check with
                  >>phpinfo(). That will also tell you whether PHP was compiled with
                  >>--disable-session.[/color]
                  >
                  > Yes, I'm editing the one PHP is using, it's /etc/php.ini, however, if you
                  > mean that it should say --disable-session under configure command at the
                  > top, it doesnt. Do I have to have disable-session compiled in ? Why is
                  > this not the default, if it's necessary to get session to work...?[/color]

                  If id did say --disable-session, then sessions would be disabled and not
                  available on the server.

                  Check the under phpinfo() for "Configurat ion File (php.ini) Path" and be
                  sure that it is set to /etc/php.ini, otherwise all your edits will do
                  nothing. Also be sure to restart apache after editing.

                  --
                  Justin Koivisto - spam@koivi.com
                  PHP POSTERS: Please use comp.lang.php for PHP related questions,
                  alt.php* groups are not recommended.

                  Comment

                  • ZoombyWoof

                    #10
                    Re: Problem with SESSION variables...

                    On Tue, 04 Nov 2003 18:27:23 +0000, Justin Koivisto wrote:
                    [color=blue]
                    > ZoombyWoof wrote:
                    >[/color]
                    *snip*
                    [color=blue]
                    >
                    > Did you restart the webserver after editing php.ini? That's a commonly
                    > overlooked step...[/color]
                    Oh yes I did.[color=blue]
                    >[/color]
                    *snip*[color=blue]
                    >
                    > Be sure that session.auto_st art is off.[/color]
                    It is[color=blue]
                    >
                    > session.save_ha ndler needs to be set to files for session.save_pa th to
                    > be used.[/color]
                    It is[color=blue]
                    >
                    > session.use_coo kies should be on if you want to use cookies. If you want
                    > to use *only* cookies, then session.use_onl y_cookies should be on as well.[/color]
                    Cookies is on[color=blue]
                    >
                    > Make sure that session.gc_maxl ifetime isn't set really low (default is
                    > 1440 seconds, or 24 minutes). Same with session.cookie_ lifetime, but 0
                    > is no exipre in this case. (Watch for session.cache_e xpire as well.)[/color]
                    Default values

                    /ZW

                    Comment

                    • ZoombyWoof

                      #11
                      Re: Problem with SESSION variables...

                      On Tue, 04 Nov 2003 18:29:44 +0000, Justin Koivisto wrote:
                      [color=blue]
                      > ZoombyWoof wrote:
                      >[color=green]
                      >> On Tue, 04 Nov 2003 18:15:12 +0000, Jon Kraft wrote:
                      >>[color=darkred]
                      >>>ZoombyWoof <zoombywoofremo ve@thishotmail. com> wrote:
                      >>>
                      >>>>I have tried all of what you suggested above, setting use_trans_sid to 1
                      >>>>didnt help. I used the link with session_name=se ssion_id, didnt help. I
                      >>>>have changed session.save_pa th to /usr/local/apache2/sessions, apache owns
                      >>>>that directory, apache is the user who runs the server, but nothing goes
                      >>>>in that directory. I have checked the cookie_params, and it doesnt contain
                      >>>>anything else from what is set as default in php.ini.
                      >>>>I dont understand this....*HELP* :-)
                      >>>
                      >>>Hm, strange, are you sure you are editing the php.ini PHP uses? Check with
                      >>>phpinfo(). That will also tell you whether PHP was compiled with
                      >>>--disable-session.[/color]
                      >>
                      >> Yes, I'm editing the one PHP is using, it's /etc/php.ini, however, if you
                      >> mean that it should say --disable-session under configure command at the
                      >> top, it doesnt. Do I have to have disable-session compiled in ? Why is
                      >> this not the default, if it's necessary to get session to work...?[/color]
                      >
                      > If id did say --disable-session, then sessions would be disabled and not
                      > available on the server.
                      >
                      > Check the under phpinfo() for "Configurat ion File (php.ini) Path" and be
                      > sure that it is set to /etc/php.ini, otherwise all your edits will do
                      > nothing. Also be sure to restart apache after editing.[/color]
                      It did not say --disable_session and I edit the right file.

                      THis is really weird...

                      /ZW

                      Comment

                      • Justin Koivisto

                        #12
                        Re: Problem with SESSION variables...

                        At this point, I say post a link to a phpinfo() call so we can better
                        see what is going on.

                        --
                        Justin Koivisto - spam@koivi.com
                        PHP POSTERS: Please use comp.lang.php for PHP related questions,
                        alt.php* groups are not recommended.

                        Comment

                        • ZoombyWoof

                          #13
                          Re: Problem with SESSION variables...

                          On Tue, 04 Nov 2003 19:39:25 +0000, Justin Koivisto wrote:
                          [color=blue]
                          > At this point, I say post a link to a phpinfo() call so we can better
                          > see what is going on.[/color]
                          THis wull be opened a couple of hours, then I close it again.



                          Thanx

                          /ZW

                          Comment

                          • Pedro

                            #14
                            Re: Problem with SESSION variables...

                            ZoombyWoof wrote:[color=blue]
                            > THis wull be opened a couple of hours, then I close it again.
                            >
                            > http://zoombywoof.dns2go.com:8029/phpinfo.php[/color]

                            session_cookie_ path = /

                            --
                            I have a spam filter working.
                            To mail me include "urkxvq" (with or without the quotes)
                            in the subject line, or your mail will be ruthlessly discarded.

                            Comment

                            • Pedro

                              #15
                              Re: Problem with SESSION variables...

                              I wrote, way too fast:[color=blue]
                              > session_cookie_ path = /[/color]
                              session.cookie_ path = /


                              session.save_pa th is local to the webserver filesystem.

                              session.cookie_ path is the HTTP path sent to the client in the cookie.

                              --
                              I have a spam filter working.
                              To mail me include "urkxvq" (with or without the quotes)
                              in the subject line, or your mail will be ruthlessly discarded.

                              Comment

                              Working...