how to force hosting server not cache php codes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • khalidbaloch
    New Member
    • Oct 2006
    • 61

    how to force hosting server not cache php codes

    hello Freind i have almost complted my first php application .. i wrote it in my local webser ..it works fine on my local server acctully the problem interpreting me is in admin page which should redirect the viewer to login page if the session is not set .. i am using this code at the starts of my admin cp page index that controll all the sub pages .
    Code:
    if (!isset($_SESSION['username']) && !isset($_SESSION['password'])) {
    header ("location: login.php");
    }
    please tell me what to do know ............
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    So what is the question or the problem?

    Ronald :cool:

    Comment

    • vssp
      Contributor
      • Jul 2006
      • 268

      #3
      Hi sorry i am not cleat what u want can u expline briefly ?

      Comment

      • khalidbaloch
        New Member
        • Oct 2006
        • 61

        #4
        sorry dear friend i forget to type the problem acctully i was in little hurry and upset bcz of this problem therefore i am reposting my question


        ..hello Freinds i have almost complted my first php application .. i wrote it in my local webser ..it works fine on my local server acctully the problem interpreting me is in admin page which should redirect the viewer to login page if the session is not set .. i am using this code at the starts of my admin cp page index that controll all the sub pages .but it is not redirecting to the login.php .instead it taking to admin cp main page ..however there no such problem on my localhost server ..hope you understad what i mean ..
        Code:
        if (!isset($_SESSION['username']) && !isset($_SESSION['password'])) {
        header ("location: login.php");
        }
        please tell me what to do know ..........

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          There is more to this problem then you show us. This code looks fine by itself and can be no reason to re-direct you to a wrong page. So show the relevant other code.

          Ronald :cool:

          Comment

          • khalidbaloch
            New Member
            • Oct 2006
            • 61

            #6
            Originally posted by ronverdonk
            There is more to this problem then you show us. This code looks fine by itself and can be no reason to re-direct you to a wrong page. So show the relevant other code.

            Ronald :cool:
            hi Ronald : this the complete code of admin cp index page
            Code:
            <?php
            header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
            header("Pragma: no-cache");
            session_start();
            if (!isset($_SESSION['username']) && !isset($_SESSION['password'])) {
            header ("location: login.php");
            exit;
            }
            include 'header.php';
            require '../dbconnect.php';
            $content="pages/$action.php";
                    if (strlen($action)==0)
                    {
                    include("pages/index.php");
                    }
                    else
                    {if (file_exists($content)) {
                    include("pages/$action.php");
                    }
                    else
                    {
                    echo "page not found";}
            }
            mysql_close();
            include 'footer.php';
            ?>
            </body>
            </html>
            i also tried by adding messege under if statment instead .and that was it

            if (!isset($_SESSI ON['username']) && !isset($_SESSIO N['password'])) {
            echo "your not loged in";
            exit;

            if seesions are not set i see this msg

            You are not loged in


            it means that if statment is working fine and this is not cache problem .the cach problem has been solved since i added other header function at starts of the page ... the problem is with header redirection ...

            Comment

            • ronverdonk
              Recognized Expert Specialist
              • Jul 2006
              • 4259

              #7
              HAve you tried to buffer? As in ob_start() and ob_end_flush? Like this
              Code:
              <?php
              ob_start();
              session_start();
              header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
              header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
              header("Pragma: no-cache");
              if (!isset($_SESSION['username']) && !isset($_SESSION['password'])) {
                 header ("location: login.php");
              exit;
              }
              
              include 'header.php';
              require '../dbconnect.php';
              $content="pages/$action.php";
                      if (strlen($action)==0)
                      {
                      include("pages/index.php");
                      }
                      else
                      {if (file_exists($content)) {
                      include("pages/$action.php");
                      }
                      else
                      {
                      echo "page not found";}
              }
              mysql_close();
              include 'footer.php';
              ob_end_flush();
              ?>
              </body>
              </html>
              Ronald :cool:

              Comment

              • khalidbaloch
                New Member
                • Oct 2006
                • 61

                #8
                no i did not tried it yet but now i will . i am unfimailar with these two functions. what do they do ?

                Comment

                • khalidbaloch
                  New Member
                  • Oct 2006
                  • 61

                  #9
                  no dear friend it is still not working .......

                  Comment

                  • ronverdonk
                    Recognized Expert Specialist
                    • Jul 2006
                    • 4259

                    #10
                    It is working at my side!!

                    Ronald :cool:

                    Comment

                    • khalidbaloch
                      New Member
                      • Oct 2006
                      • 61

                      #11
                      Originally posted by ronverdonk
                      It is working at my side!!

                      Ronald :cool:
                      it is working even in my local webserver but not working on ifastnet.com hosting server and it does not display any php error ... is there any command that force this server to show php errors ..

                      Comment

                      • ronverdonk
                        Recognized Expert Specialist
                        • Jul 2006
                        • 4259

                        #12
                        You will have to contact the administrator of that server. Not very much you can do when he/she has disabled functions or prevents some processing!

                        Ronald :cool:

                        Comment

                        Working...