logout script not working properly.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kamill
    New Member
    • Dec 2006
    • 71

    logout script not working properly.

    I have done a logout page for logout from admin section and provides a link to logout from admin section.Wheneve r i clicked on logout link it redirected to index.php of admin section......BU T when i am tring to go back threw back button of Browser....it send me last visted pages(means sessons not expire properly). How can i solve it... One more thing is that the script is working properly on localhost....pr oblem occures when i uploaded it on server.
    code of logout is following....
    [php]<?phpsession_st art();
    if($_SESSION['user_id']!="" && $_SESSION['user_pwd']!="")
    {
    $_SESSION=array ();
    session_unset() ;
    session_destroy ();
    ?>
    <script>
    window.location .href="index.ph p";
    </script>
    <?php
    }
    else
    { ?>
    <script>
    window.location .href="index.ph p";
    </script>
    <?php } ?>[/php]
    Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that. - moderator
    Last edited by ronverdonk; Mar 8 '08, 01:18 PM. Reason: code tags
  • cassbiz
    New Member
    • Oct 2006
    • 202

    #2
    Not too familiar with the actual "logout" but I just checked a couple of different scripts that I have and they all call a logout or similar function.


    Code:
    logout();
    Here is the function

    Code:
    function logout()
    {
        $sql="UPDATE users
        SET UserSession=NULL
        WHERE UserSession='".session_id()."'";
         mysql_query($sql);
    }

    Comment

    • Velhari
      New Member
      • Sep 2006
      • 46

      #3
      Hi,

      You are facing the problem after logout, the user presses back button in the browser window it will shows all the pages visited by him/her earlier know.....

      This problem can be easily removed by, you can check for the session variable for userid is set in each and every pages..... If suppose this condition is violated means, you have to forward it to the index page.....

      Like just for an example...

      [PHP]
      session_start() ;
      if ( $_SESSION['userid']=="" )
      header("index.p hp");
      [/PHP]


      Originally posted by kamill
      I have done a logout page for logout from admin section and provides a link to logout from admin section.Wheneve r i clicked on logout link it redirected to index.php of admin section......BU T when i am tring to go back threw back button of Browser....it send me last visted pages(means sessons not expire properly). How can i solve it... One more thing is that the script is working properly on localhost....pr oblem occures when i uploaded it on server.
      code of logout is following....
      ///////////////////////////////////////////////////////////////////////////////////////////////////
      <?phpsession_st art();

      if($_SESSION['user_id']!="" && $_SESSION['user_pwd']!="")
      {

      $_SESSION=array ();
      session_unset() ;
      session_destroy ();
      ?>

      <script>
      window.location .href="index.ph p";
      </script>
      <?php

      }

      else
      { ?>

      <script>
      window.location .href="index.ph p";
      </script>

      <?php } ?>

      /////////////////////////////////////////////////////////////////////////////////////////////
      Last edited by Velhari; Jan 5 '07, 08:29 PM. Reason: Adding Essence

      Comment

      • kamill
        New Member
        • Dec 2006
        • 71

        #4
        Originally posted by Velhari
        Hi,

        You are facing the problem after logout, the user presses back button in the browser window it will shows all the pages visited by him/her earlier know.....

        This problem can be easily removed by, you can check for the session variable for userid is set in each and every pages..... If suppose this condition is violated means, you have to forward it to the index page.....
        Like just for an example...
        [PHP]
        session_start() ;
        if ( $_SESSION['userid']=="" )
        header("index.p hp");
        [/PHP]
        i have done it but it working on localhost but not working on server after uploading...my code is like this..
        [php]<?php session_start() ;
        if($_SESSION['username']=="" && $_SESSION['pwd']=="" )
        {
        ?>
        <script> window.location .href="index.ph p";</script>
        <?php
        }
        else
        {
        rest of the code.....
        }[/php]
        2nd warning: Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

        moderator
        Last edited by ronverdonk; Mar 8 '08, 01:20 PM. Reason: code tags

        Comment

        • kamill
          New Member
          • Dec 2006
          • 71

          #5
          i am again putting my code in a mannered way.....help me ASAP
          [PHP]<?php session_start() ;
          if($_SESSION['username']=="" && $_SESSION['pwd']=="" )
          {
          ?>
          <script> window.location .href="index.ph p";</script>
          <?php
          }
          else
          {
          rest of the code.....
          }[/PHP]

          Comment

          • kamill
            New Member
            • Dec 2006
            • 71

            #6
            Please help me as soon as possible......i ts very urgent for me.
            thanks in advance....

            Comment

            • kamill
              New Member
              • Dec 2006
              • 71

              #7
              i am waiting for help....

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                You have just posted this in a seperate thread.
                Dont double post

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Originally posted by kamill
                  i am waiting for help....
                  The session HAS expired, but you're viewing a cached version of the page.
                  I.E, the browser has stored that page in it's history.

                  Comment

                  • TheServant
                    Recognized Expert Top Contributor
                    • Feb 2008
                    • 1168

                    #10
                    [PHP]<?php
                    session_start()
                    session_destroy ()
                    ?>

                    {redirect code}[/PHP]

                    This way it doesn't matter how many variables you have it will get rid of them all. If this doesn't work, it is the browser storing information somehow.

                    Comment

                    • Markus
                      Recognized Expert Expert
                      • Jun 2007
                      • 6092

                      #11
                      Originally posted by TheServant
                      [PHP]<?php
                      session_start()
                      session_destroy ()
                      ?>

                      {redirect code}[/PHP]

                      This way it doesn't matter how many variables you have it will get rid of them all. If this doesn't work, it is the browser storing information somehow.
                      Like i already said, the browser stores the page in it's cache so people can use the back button.

                      Comment

                      • Ravigandha
                        New Member
                        • Mar 2008
                        • 17

                        #12
                        Hi everbody,
                        I have also faced this kind of problem like session working in localhost and not working when uploaded, Now i got solution for this.
                        I have contact the hosting server and described the issue,then they came to my aid and help me out. The problem was "Due to some permission issue in session directory " that's why we were facing this problem.

                        The problem I faced and how it is solved i mention it,But i m not an expert!
                        thanks

                        Comment

                        • RoninOni
                          New Member
                          • Mar 2008
                          • 9

                          #13
                          here is a trick, before sending them to the home page after logout, send them to a redirect.php page which has only
                          [PHP]<?php
                          header("locatio n: /index.php");
                          ?>[/PHP]

                          That way, when they click the back button, its the redirect page which takes them back to the home page this will help resolve the issue of the cached pages, though they can still use the back drop down to go to whatever page they were on, it will make it harder, and many users may nbot realize this option

                          Comment

                          Working...