DIssapearing/reappearing Session variables

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

    #1

    DIssapearing/reappearing Session variables

    Hello,

    Thought I'd try this forum as I got some useful help from here before.

    Anyway, this is the problem; I have a simple authorisation script (in
    PHP):



    It works great locally but when I upload it no longer works well; the
    problem is that it takes me to the login page whenever I move forward
    in the photo gallery; see :

    www.multidome.co.uk/test/gallery.php (Username= test; Password=
    test)

    Sometime, you just need to refresh the login page to be logged you
    back in! I think it has something to do with the $authdata session
    variable.

    Does anybody know what might cause this? I think it might be the same
    problem as this:



    Thanks.

    Duncs

    The code for all the php pages can be seen by changing the .php
    to .txt, i.e:






  • iktorn

    #2
    Re: DIssapearing/reappearing Session variables

    dangerd napisał(a):
    Hello,
    >
    Thought I'd try this forum as I got some useful help from here before.
    >
    >
    Duncs
    >
    The code for all the php pages can be seen by changing the .php
    to .txt, i.e:
    >
    Hello, first of all

    is wrong - you should call session_start() before sending any data to
    the browser (at the beggining of your scripts).
    Write it for example one line after error_reporting (null);
    (and remove it from auth() function).

    Secondly, don't use session_registe r, just write anything to $_SESSION
    (if you are using PHP 4.1 or later).


    --
    Wiktor Walc

    Comment

    • dangerd

      #3
      Re: DIssapearing/reappearing Session variables

      On Apr 9, 8:52 pm, iktorn <s...@phpfreela ncer.netwrote:
      dangerd napisał(a):
      >
      Hello,
      >
      Thought I'd try this forum as I got some useful help from here before.
      >
      Duncs
      >
      The code for all the php pages can be seen by changing the .php
      to .txt, i.e:
      >
      Hello, first of allhttp://www.multidome.c o.uk/test/authorisation.t xt
      is wrong - you should call session_start() before sending any data to
      the browser (at the beggining of your scripts).
      Write it for example one line after error_reporting (null);
      (and remove it from auth() function).
      >
      Secondly, don't use session_registe r, just write anything to $_SESSION
      (if you are using PHP 4.1 or later).
      >
      --
      Wiktor Walchttp://phpfreelancer.n et
      Thanks for the help Wiktor,
      >is wrong - you should call session_start() before sending any data to
      the browser (at the beggining of your scripts).
      Write it for example one line after error_reporting (null);
      (and remove it from auth() function).
      The point of having it inside the function is to only start the
      session if a session has not already been started. With that in mind,
      do you still think I should take it out of the function?

      Duncs

      Comment

      • dangerd

        #4
        Re: DIssapearing/reappearing Session variables

        On Apr 9, 8:52 pm, iktorn <s...@phpfreela ncer.netwrote:
        dangerd napisał(a):
        >
        Hello,
        >
        Thought I'd try this forum as I got some useful help from here before.
        >
        Duncs
        >
        The code for all the php pages can be seen by changing the .php
        to .txt, i.e:
        >
        Hello, first of allhttp://www.multidome.c o.uk/test/authorisation.t xt
        is wrong - you should call session_start() before sending any data to
        the browser (at the beggining of your scripts).
        Write it for example one line after error_reporting (null);
        (and remove it from auth() function).
        >
        Secondly, don't use session_registe r, just write anything to $_SESSION
        (if you are using PHP 4.1 or later).
        >
        --
        Wiktor Walchttp://phpfreelancer.n et
        Hello,

        I got rid of the session_registe r() and the problem persists. I think
        what is happening is that the $_SESSION[$authdata] (I took your
        advise on board) dissapears after five or so refreshes but then
        reappears after another refresh. There does not seem to be a pattern
        on the number of refreshes it takes for $authdata to dissapear.
        Strange...

        Duncs

        Comment

        • iktorn

          #5
          Re: DIssapearing/reappearing Session variables

          dangerd napisał(a):
          On Apr 9, 8:52 pm, iktorn <s...@phpfreela ncer.netwrote:
          >dangerd napisał(a):
          >>
          >
          Hello,
          >
          I got rid of the session_registe r() and the problem persists. I think
          what is happening is that the $_SESSION[$authdata] (I took your
          advise on board) dissapears after five or so refreshes but then
          reappears after another refresh. There does not seem to be a pattern
          on the number of refreshes it takes for $authdata to dissapear.
          Strange...
          >
          Duncs
          >
          There is always some reasonable solution for such problems ;)

          In http://www.multidome.co.uk/test/gallery.txt authorisation.p hp
          is included afer DOCTYPE declaration, therefore session_start()
          isn't called at the beginning of the script and your session is being
          lost (if you don't have some output buffering turned on).

          The proper way of using session is:

          <?
          //must be called on every page
          session_start() ;
          //after calling session_start() , assign anything to $_SESSION
          $_SESSION['foo']='bar';
          //now let's generate HTML
          ?>
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
          "http://www.w3.org/TR/html4/strict.dtd">
          <title>Multidom e- The UK's favorite telescopic pool enclosure.</TITLE>
          <?
          //you can use $_SESSION also after sending text to the browser
          $_SESSION['foo2']='kkk';
          ?>

          If it didn't solve your problem, turn on debugging (including E_NOTICE
          reporting) - it's the best way to find some bugs in code.

          --
          Wiktor Walc

          Comment

          • dangerd

            #6
            Re: DIssapearing/reappearing Session variables

            On Apr 10, 6:44 am, iktorn <s...@phpfreela ncer.netwrote:
            dangerd napisał(a):
            >
            On Apr 9, 8:52 pm, iktorn <s...@phpfreela ncer.netwrote:
            dangerd napisał(a):
            >
            Hello,
            >
            I got rid of the session_registe r() and the problem persists. I think
            what is happening is that the $_SESSION[$authdata] (I took your
            advise on board) dissapears after five or so refreshes but then
            reappears after another refresh. There does not seem to be a pattern
            on the number of refreshes it takes for $authdata to dissapear.
            Strange...
            >
            Duncs
            >
            There is always some reasonable solution for such problems ;)
            >
            Inhttp://www.multidome.c o.uk/test/gallery.txtauth orisation.php
            is included afer DOCTYPE declaration, therefore session_start()
            isn't called at the beginning of the script and your session is being
            lost (if you don't have some output buffering turned on).
            >
            The proper way of using session is:
            >
            <?
            //must be called on every page
            session_start() ;
            //after calling session_start() , assign anything to $_SESSION
            $_SESSION['foo']='bar';
            //now let's generate HTML
            ?>
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
            <title>Multidom e- The UK's favorite telescopic pool enclosure.</TITLE>
            <?
            //you can use $_SESSION also after sending text to the browser
            $_SESSION['foo2']='kkk';
            ?>
            >
            If it didn't solve your problem, turn on debugging (including E_NOTICE
            reporting) - it's the best way to find some bugs in code.
            >
            --
            Wiktor Walchttp://phpfreelancer.n et
            Wiktor,

            I have tried what you suggested but the problem, still persists. I
            have updated the txt code so you can see for yourself.
            ....any more ideas?

            Thanks

            Duncs

            Comment

            • iktorn

              #7
              Re: DIssapearing/reappearing Session variables

              dangerd napisał(a):
              On Apr 10, 6:44 am, iktorn <s...@phpfreela ncer.netwrote:
              >dangerd napisał(a):
              >>
              Wiktor,
              >
              I have tried what you suggested but the problem, still persists. I
              have updated the txt code so you can see for yourself.
              ...any more ideas?
              >
              Thanks
              >
              Duncs
              >
              replace auth function with these piece of code, should work

              function auth ( $login = '', $password = '' )
              {
              if (isset($_SESSIO N['authdata']['login'])) {
              return TRUE;
              }
              elseif (!empty($login) )
              {
              if ( $login == myuser && $password == mypass or $login ==
              myuser2 && $password == mypass2 ) {
              $_SESSION['authdata'] = array ( "login" =$login );
              return TRUE;
              }

              $_SESSION['authdata'] = array();
              return FALSE;
              }
              else {
              return FALSE;
              }
              }

              your previous function used "global $authdata;" - variable $authdata
              would only exist if you had register_global s turned on.


              --
              Wiktor Walc

              Comment

              • dangerd

                #8
                Re: DIssapearing/reappearing Session variables

                On Apr 10, 7:53 am, iktorn <s...@phpfreela ncer.netwrote:
                dangerd napisał(a):
                >
                On Apr 10, 6:44 am, iktorn <s...@phpfreela ncer.netwrote:
                dangerd napisał(a):
                >
                Wiktor,
                >
                I have tried what you suggested but the problem, still persists. I
                have updated the txt code so you can see for yourself.
                ...any more ideas?
                >
                Thanks
                >
                Duncs
                >
                replace auth function with these piece of code, should work
                >
                function auth ( $login = '', $password = '' )
                {
                if (isset($_SESSIO N['authdata']['login'])) {
                return TRUE;
                }
                elseif (!empty($login) )
                {
                if ( $login == myuser && $password == mypass or $login ==
                myuser2 && $password == mypass2 ) {
                $_SESSION['authdata'] = array ( "login" =$login );
                return TRUE;
                }
                >
                $_SESSION['authdata'] = array();
                return FALSE;
                }
                else {
                return FALSE;
                }
                >
                }
                >
                your previous function used "global $authdata;" - variable $authdata
                would only exist if you had register_global s turned on.
                >
                --
                Wiktor Walchttp://phpfreelancer.n et
                Ace!!

                You nailed it. You have made my day!

                You are a king amongst men my friend.

                Thanks

                Comment

                Working...