session data getting lost

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jkmambo@gmail.com

    #1

    session data getting lost

    Session data is getting lost in PHP version 4.4.1 which used to work in
    version 4.3.3

    The code is similar to the one below

    Assume the file is called count.php which requires a parameter
    productid;

    session_start() ;
    if (!isset($_SESSI ON['countAccess'])) $_SESSION['countAccess'] = 0;
    else $_SESSION['countAccess']++;

    echo $_SESSION['countAccess'];


    if I call the script with a parameter for example
    count.php?produ ctid=78

    when I press refresh button $_SESSION['countAccess'] does not get
    incremented but if I call it without the parameter,
    $_SESSION['countAccess'] gets incremented.
    I am also losing data if I call another script.

    Does anyone know what's going on here?

    Thank you

  • Erwin Moller

    #2
    Re: session data getting lost

    jkmambo@gmail.c om wrote:
    [color=blue]
    > Session data is getting lost in PHP version 4.4.1 which used to work in
    > version 4.3.3
    >
    > The code is similar to the one below
    >
    > Assume the file is called count.php which requires a parameter
    > productid;
    >
    > session_start() ;
    > if (!isset($_SESSI ON['countAccess'])) $_SESSION['countAccess'] = 0;
    > else $_SESSION['countAccess']++;
    >
    > echo $_SESSION['countAccess'];
    >
    >[/color]

    Why don't you use {} to mark your logical blocks?
    This is PHP, not python. ;-)

    Like:
    session_start() ;
    if (!isset($_SESSI ON['countAccess'])) {
    $_SESSION['countAccess'] = 0;
    } else {
    $_SESSION['countAccess']++;
    }

    echo $_SESSION['countAccess'];

    [color=blue]
    > if I call the script with a parameter for example
    > count.php?produ ctid=78
    >
    > when I press refresh button $_SESSION['countAccess'] does not get
    > incremented but if I call it without the parameter,
    > $_SESSION['countAccess'] gets incremented.[/color]


    That ?productid=78 has nothing to do with the SESSION.
    It will appear in $_GET, not $_SESSION.
    So this is very surprising.
    Do you have more code, without {}, that might interfere?
    If yes: fix it, and if the problem persists, show us the code.
    [color=blue]
    > I am also losing data if I call another script.
    >
    > Does anyone know what's going on here?
    >
    > Thank you[/color]

    Regards,
    Erwin Moller

    Comment

    • Ian B

      #3
      Re: session data getting lost

      Works for me on 3.3.10 and 4.4.1

      Must be one of your settings or something elsewhere in the script

      Comment

      • jkmambo@gmail.com

        #4
        Re: session data getting lost

        When you use one statement in an if-else block you dont need {} for all
        C type languages. {} are only used to group statements

        Comment

        • jkmambo@gmail.com

          #5
          Re: session data getting lost

          I apologize the problem was not with the parameter. The code is working
          sometimes and other times it does not work whether I am using a
          paramter or not. The first time I tested the ecript today it was not
          working, then I addeda simple echo statement to display a string. Then
          the script worked OK. This is the setting of my session in php.ini



          session
          Session Support enabled
          Registered save handlers files user

          Directive Local Value Master Value
          session.auto_st art Off Off
          session.bug_com pat_42 On On
          session.bug_com pat_warn On On
          session.cache_e xpire 180 180
          session.cache_l imiter nocache nocache
          session.cookie_ domain no value no value
          session.cookie_ lifetime 0 0
          session.cookie_ path / /
          session.cookie_ secure Off Off
          session.entropy _file no value no value
          session.entropy _length 0 0
          session.gc_divi sor 100 100
          session.gc_maxl ifetime 1440 1440
          session.gc_prob ability 1 1
          session.name PHPSESSID PHPSESSID
          session.referer _check no value no value
          session.save_ha ndler files files
          session.save_pa th /tmp /tmp
          session.seriali ze_handler php php
          session.use_coo kies On On
          session.use_onl y_cookies Off Off
          session.use_tra ns_sid Off Off

          Comment

          • jkmambo@gmail.com

            #6
            Re: session data getting lost

            I apologize the problem was not with the parameter. The code is working
            sometimes and other times it does not work whether I am using a
            paramter or not. The first time I tested the ecript today it was not
            working, then I addeda simple echo statement to display a string. Then
            the script worked OK. This is the setting of my session in php.ini



            session
            Session Support enabled
            Registered save handlers files user

            Directive Local Value Master Value
            session.auto_st art Off Off
            session.bug_com pat_42 On On
            session.bug_com pat_warn On On
            session.cache_e xpire 180 180
            session.cache_l imiter nocache nocache
            session.cookie_ domain no value no value
            session.cookie_ lifetime 0 0
            session.cookie_ path / /
            session.cookie_ secure Off Off
            session.entropy _file no value no value
            session.entropy _length 0 0
            session.gc_divi sor 100 100
            session.gc_maxl ifetime 1440 1440
            session.gc_prob ability 1 1
            session.name PHPSESSID PHPSESSID
            session.referer _check no value no value
            session.save_ha ndler files files
            session.save_pa th /tmp /tmp
            session.seriali ze_handler php php
            session.use_coo kies On On
            session.use_onl y_cookies Off Off
            session.use_tra ns_sid Off Off

            Comment

            • jkmambo@gmail.com

              #7
              Re: session data getting lost

              I have discovered what the problem was. I installed Zone Alarm Internet
              Security Suite and it appears its blocking the session information. I
              have disabled it and the system is working fine now.

              Comment

              • Ian B

                #8
                Re: session data getting lost

                Sorry, still works every time, even with your ini file - could it be a
                caching thing?

                What OS and browser are you on?

                Comment

                • Ian B

                  #9
                  Re: session data getting lost

                  Sorry, still works every time, even with your ini file - could it be a
                  caching thing?

                  What OS and browser are you on?

                  Comment

                  • jkmambo@gmail.com

                    #10
                    Re: session data getting lost

                    The problem was being caused by zone alarm internet security software
                    blocking sessions. I do not understand why it's doing this for. I
                    wanted to buy it but now I will think twice before I buy it.
                    I thought the problem could have been due to my web hosting company
                    updating the PHP version and not setting up the session values
                    properly.
                    Thank you for taking your time to help me with this problem

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: session data getting lost

                      jkmambo@gmail.c om wrote:[color=blue]
                      > When you use one statement in an if-else block you dont need {} for all
                      > C type languages. {} are only used to group statements
                      >[/color]

                      No, you don't *need* them. However, I still add them in my code.
                      Overall it makes things more readable, IMHO.

                      It also means I don't have unanticipated problems when I add another
                      statement to a then or else clause.

                      --
                      =============== ===
                      Remove the "x" from my email address
                      Jerry Stuckle
                      JDS Computer Training Corp.
                      jstucklex@attgl obal.net
                      =============== ===

                      Comment

                      • jkmambo@gmail.com

                        #12
                        Re: session data getting lost

                        Erwin as implying that the braces are required in PHP even for one
                        statement but which they are not. In my opinion its more legible not to
                        have the braces and the code looks shorter.

                        Comment

                        • Ian B

                          #13
                          Re: session data getting lost

                          I'd do a single line "if" as

                          if (!isset($_SESSI ON['countAccess'])) $_SESSION['countAccess'] = 0;

                          but if I had an else, i'd probably use braces, but I'd lay it out:

                          if (!isset($_SESSI ON['countAccess']))
                          {
                          $_SESSION['countAccess'] = 0;
                          }
                          else
                          {
                          $_SESSION['countAccess']++;
                          }

                          Comment

                          • Ian

                            #14
                            Re: session data getting lost

                            jkmambo@gmail.c om wrote:[color=blue]
                            > Erwin as implying that the braces are required in PHP even for one
                            > statement but which they are not. In my opinion its more legible not to
                            > have the braces and the code looks shorter.
                            >[/color]
                            And harder to follow and maintain....

                            Ian

                            Comment

                            • Ian

                              #15
                              Re: session data getting lost

                              jkmambo@gmail.c om wrote:[color=blue]
                              > The problem was being caused by zone alarm internet security software
                              > blocking sessions.[/color]

                              Was it blocking the session cookie? If so, this is a more general problem.

                              Ian

                              Comment

                              Working...