Preventing Browser-caching between Frames

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

    Preventing Browser-caching between Frames

    Hello,
    my web-application uses two frames, one with a list of database
    records, one with a record detail view. From the detail view there is
    "mark" function that will mark the respective record in the list frame
    (with a special color).
    Now this mark function is meant to toggle the mark status in the list
    frame, i.e. switch it on with the first click and off with the second.
    Problem is, the marking works, but the second click will not have any
    effect. Only when I click on another link in the list frame and _then_
    click "mark" again will the marking be switched off.
    I assume this is due to the browser caching the request, and when it
    gets two times the same request (i.e. "list_records.p hp?marknode=42" ),
    just ignores the second one. All no-cache parameters are already set in
    the headers, like:
    header("Cache-Control: no-store, no-cache, must-revalidate");

    (as described in the PHP manual), but this doesn't seem to work.
    Or maybe the described behaviour is based on something else?
    Thanks for hints!

  • Erwin Moller

    #2
    Re: Preventing Browser-caching between Frames

    bvdb wrote:
    Hello,
    my web-application uses two frames, one with a list of database
    records, one with a record detail view. From the detail view there is
    "mark" function that will mark the respective record in the list frame
    (with a special color).
    Now this mark function is meant to toggle the mark status in the list
    frame, i.e. switch it on with the first click and off with the second.
    Problem is, the marking works, but the second click will not have any
    effect. Only when I click on another link in the list frame and _then_
    click "mark" again will the marking be switched off.
    I assume this is due to the browser caching the request, and when it
    gets two times the same request (i.e. "list_records.p hp?marknode=42" ),
    just ignores the second one. All no-cache parameters are already set in
    the headers, like:
    header("Cache-Control: no-store, no-cache, must-revalidate");
    >
    (as described in the PHP manual), but this doesn't seem to work.
    Or maybe the described behaviour is based on something else?
    Thanks for hints!
    Hi,

    [Why not post this is a Javascript newsgroup?]

    Two things:
    1) You didn't describe how you detect the click.
    Try using the onClick-event handler in Javascript to test is your browser is
    missing clicks. Just make a function that says hello.
    <span onClick="alert( 'I am clicked');">som e record</span>

    2) Caching. *IF* this is a caching-issue, just append some timestamp to the
    url to prevent caching.
    From php:
    <a href="detailedv iew.php?recordi d=<?= $recordid ?>&t=<?= microtime() ?>">
    recordlink here</a>

    I just made up the recordid, I guess you managed that part already.
    The addition t=5432897659834 75 makes sure every url is different each time.
    That will prevent retrieving cached records.

    Hope that helps.
    If not, post some examplecode.

    Regards,
    Erwin

    Comment

    • bvdb

      #3
      Re: Preventing Browser-caching between Frames

      Hello,
      Erwin Moller wrote:
      ....
      [Why not post this is a Javascript newsgroup?]
      Because there is no Javascript involved in my code, just HTML and PHP.
      Two things:
      1) You didn't describe how you detect the click.
      Try using the onClick-event handler in Javascript ...
      My code works fine:
      If I load the list frame in a separate window and reload it the marking
      gets toggled on and off each time.
      2) Caching. *IF* this is a caching-issue, just append some timestamp to the
      url to prevent caching.
      This only works if the whole page would be regenerated - but the record
      frame remains the same, so the timestamp would also stay the same which
      makes it senseless.

      Comment

      • Jerry Stuckle

        #4
        Re: Preventing Browser-caching between Frames

        bvdb wrote:
        Hello,
        Erwin Moller wrote:
        ...
        >
        >>[Why not post this is a Javascript newsgroup?]
        >
        >
        Because there is no Javascript involved in my code, just HTML and PHP.
        >
        >
        >>Two things:
        >>1) You didn't describe how you detect the click.
        >>Try using the onClick-event handler in Javascript ...
        >
        >
        My code works fine:
        If I load the list frame in a separate window and reload it the marking
        gets toggled on and off each time.
        >
        >
        >>2) Caching. *IF* this is a caching-issue, just append some timestamp to the
        >>url to prevent caching.
        >
        >
        This only works if the whole page would be regenerated - but the record
        frame remains the same, so the timestamp would also stay the same which
        makes it senseless.
        >
        The problem is each frame pretty much acts like a separate window from
        the server's POV. That is, you can't force a frame to load from the
        server end. You can update your data in one frame and send it to the
        server. But only that frame will get updated - PHP can't force another
        frame to get updated.

        For that you'll have to use Javascript to request the second frame be
        reloaded.

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

        Comment

        • bvdb

          #5
          Re: Preventing Browser-caching between Frames

          Hello,
          Jerry Stuckle wrote:
          The problem is each frame pretty much acts like a separate window from
          the server's POV. That is, you can't force a frame to load from the
          server end.
          Of course not. That's why I'm calling it from the record-frame with a
          target='listfra me' clause.
          It works once and then again after I do something else in the list
          frame. So my code works, the frame structure is okay, only the browser
          ignores the second (same) call.
          For that you'll have to use Javascript to request the second frame be
          reloaded.
          No, sorry, Javascript really is not a question nor a solution here.

          Comment

          • Jerry Stuckle

            #6
            Re: Preventing Browser-caching between Frames

            bvdb wrote:
            Hello,
            Jerry Stuckle wrote:
            >
            >>The problem is each frame pretty much acts like a separate window from
            >>the server's POV. That is, you can't force a frame to load from the
            >>server end.
            >
            >
            Of course not. That's why I'm calling it from the record-frame with a
            target='listfra me' clause.
            It works once and then again after I do something else in the list
            frame. So my code works, the frame structure is okay, only the browser
            ignores the second (same) call.
            >
            >
            >>For that you'll have to use Javascript to request the second frame be
            >>reloaded.
            >
            >
            No, sorry, Javascript really is not a question nor a solution here.
            >
            In that case I'm not sure why it would fail. But it does not look like
            a PHP problem - probably something in the HTML. You might try alt.html
            for more help.

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

            Comment

            • bvdb

              #7
              Re: Preventing Browser-caching between Frames

              Jerry, it is not a downright "PHP problem", more a general "web server
              programming problem" - but as the web server programming language of my
              choice happens to be PHP, and I assume(d) many PHP programmers face
              the same problem with frames, I posted the question here.
              Maybe there is someone out there with a practical solution.

              Comment

              • Jerry Stuckle

                #8
                Re: Preventing Browser-caching between Frames

                bvdb wrote:
                Jerry, it is not a downright "PHP problem", more a general "web server
                programming problem" - but as the web server programming language of my
                choice happens to be PHP, and I assume(d) many PHP programmers face
                the same problem with frames, I posted the question here.
                Maybe there is someone out there with a practical solution.
                >
                No, it isn't. And it isn't a PHP problem at all.

                Don't you think you would get a better response on a group which would
                handle this type of problem - and has cross-language support? Such as
                alt.html?

                Just because you're using PHP doesn't necessarily make this the "best"
                group. And just because you're having a particular (non-php) problem
                doesn't mean others have.

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

                Comment

                • bvdb

                  #9
                  Re: Preventing Browser-caching between Frames

                  Hello,
                  Jerry Stuckle wrote:
                  bvdb wrote:
                  ....
                  Maybe there is someone out there with a practical solution.
                  >
                  No, it isn't.
                  How can you know who is reading and posting in this newsgroup?
                  Do you have a list of people who is willing to post here?
                  Seems like you're a very arrogant person.
                  And it isn't a PHP problem at all.
                  It's tighly connected to PHP.
                  PHP offers the header() function and describes in the manual how to use
                  it to avoid this browser behaviour. So it fits very well into PHP
                  questions, better than HTML.
                  Just because you're using PHP doesn't necessarily make this the "best"
                  group.
                  But a very good choice. Until you stepped in.

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: Preventing Browser-caching between Frames

                    bvdb wrote:
                    Hello,
                    Jerry Stuckle wrote:
                    >
                    >>bvdb wrote:
                    >
                    ...
                    >
                    >>>Maybe there is someone out there with a practical solution.
                    >>
                    >>No, it isn't.
                    >
                    >
                    How can you know who is reading and posting in this newsgroup?
                    Do you have a list of people who is willing to post here?
                    Seems like you're a very arrogant person.
                    >
                    No, I'm trying to direct you to the best possible resource for your
                    question. But you are too thick-skulled to understand it.
                    >
                    >>And it isn't a PHP problem at all.
                    >
                    >
                    It's tighly connected to PHP.
                    PHP offers the header() function and describes in the manual how to use
                    it to avoid this browser behaviour. So it fits very well into PHP
                    questions, better than HTML.
                    >
                    No, it's not "tightly connected to PHP". This is strictly HTML and
                    browser behavior. All the header() function does is send a header to
                    the browser. This would be exactly the same if the header were
                    generated in PHP, Perl, VBScript or even HTML itself. PHP has nothing
                    to do with it other than sending the header (just like the other
                    languages would have nothing to do with it).
                    >
                    >>Just because you're using PHP doesn't necessarily make this the "best"
                    >>group.
                    >
                    >
                    But a very good choice. Until you stepped in.
                    >
                    No, it was not a good choice. Look how many answers you've gotten.

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

                    Comment

                    • bvdb

                      #11
                      Re: Preventing Browser-caching between Frames

                      Hello,
                      Jerry Stuckle wrote:
                      No, I'm trying to direct you to the best possible resource for your
                      question. But you are too thick-skulled to understand it.
                      It's not yours or anybodys job to "direct" anybody else to something.
                      The idea of a newsgroup is: If you have something to say to answer the
                      question, say it, if not, stay quiet.
                      No, it's not "tightly connected to PHP". This is strictly HTML and
                      browser behavior.
                      Nonsense, obviously you have not read my description.
                      If it was pure HTML, the same link would fetch the same content and
                      thus render the same page.
                      The whole question only makes sense with a server application.
                      This would be exactly the same if the header were
                      generated in PHP, Perl, VBScript
                      Okay. So now it's PHP.
                      .. or even HTML itself.
                      HTML cannot generate HTTP-headers like the header()-function does.
                      You don't know what you're talking about.
                      No, it was not a good choice. Look how many answers you've gotten.
                      The thread was poisoned by an arrogant wannabe.
                      So, sad enough, we can merely expect people with a constructive
                      attitude to join in (any more).

                      Comment

                      • Jerry Stuckle

                        #12
                        Re: Preventing Browser-caching between Frames

                        bvdb wrote:
                        Hello,
                        Jerry Stuckle wrote:
                        >
                        >>No, I'm trying to direct you to the best possible resource for your
                        >>question. But you are too thick-skulled to understand it.
                        >
                        >
                        It's not yours or anybodys job to "direct" anybody else to something.
                        The idea of a newsgroup is: If you have something to say to answer the
                        question, say it, if not, stay quiet.
                        >
                        No, it's not my "job". However, I do try to help people. If it's
                        something pertinent to this group and I can handle it, I do. If it's
                        pertinent to this group and I can't, I let someone else. And if there
                        is a better group to ask the question in, I try to steer the person that
                        way, even if he being an arrogant asshole.
                        >
                        >>No, it's not "tightly connected to PHP". This is strictly HTML and
                        >>browser behavior.
                        >
                        >
                        Nonsense, obviously you have not read my description.
                        If it was pure HTML, the same link would fetch the same content and
                        thus render the same page.
                        The whole question only makes sense with a server application.
                        >
                        Not at all. Something on the server that is completely independent
                        (i.e. a cron job that runs every 10 seconds) can replace the HTML pages
                        between requests from the browser. The same link would retrieve
                        different content every 10 seconds. But it would be static HTML.
                        >
                        >>This would be exactly the same if the header were
                        >>generated in PHP, Perl, VBScript
                        >
                        >
                        Okay. So now it's PHP.
                        >
                        Right. It's generated by PHP. But the problem is not a PHP problem.
                        >
                        >>.. or even HTML itself.
                        >
                        >
                        HTML cannot generate HTTP-headers like the header()-function does.
                        You don't know what you're talking about.
                        >
                        Actually, I do. Apache/IIS can and does generate EXACTLY the same type
                        of headers as PHP does. To an IP trace sometime and figure it out. The
                        only difference is that these headers are preset in the httpd.conf file.
                        But I doubt you know anything about that.

                        Unlike you, I've been dealing with webserver intimately for around 15
                        years - including internals. I know *exactly* what I'm talking about.
                        >
                        >>No, it was not a good choice. Look how many answers you've gotten.
                        >
                        >
                        The thread was poisoned by an arrogant wannabe.
                        So, sad enough, we can merely expect people with a constructive
                        attitude to join in (any more).
                        >
                        Not at all. It was someone who didn't know what newsgroup to ask it in.
                        There is nothing stopping anyone else from responding.

                        I'll expect the apology when you get your answer and find it's not a PHP
                        problem at all. But I know I won't get it. Guys like you never do.

                        Go ahead - spin your wheels. I don't need to put up with your asinine
                        abuse. So much for trying to help a complete idiot.

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

                        Comment

                        • bvdb

                          #13
                          Re: Preventing Browser-caching between Frames

                          Jerry Stuckle schrieb:
                          ....
                          No, it's not my "job". However, I do try to help people.
                          "Help", hmm. Go out and do some real help.
                          The whole question only makes sense with a server application.
                          >
                          Not at all. Something on the server that is completely independent
                          (i.e. a cron job that runs every 10 seconds) can replace the HTML pages
                          between requests from the browser.
                          :-))
                          HTML cannot generate HTTP-headers like the header()-function does.
                          You don't know what you're talking about.
                          >
                          Actually, I do. Apache/IIS can and does generate EXACTLY the same type
                          of headers as PHP does.
                          Yes, of course, but it is not directed by the HTML code.
                          And HTML code is what a HTML newsgroup is about.
                          So much for trying to help a complete idiot.
                          So you learned something in the end. Fine.

                          Comment

                          • Jerry Stuckle

                            #14
                            Re: Preventing Browser-caching between Frames

                            bvdb wrote:
                            Jerry Stuckle schrieb:
                            ...
                            >
                            >>No, it's not my "job". However, I do try to help people.
                            >
                            >
                            "Help", hmm. Go out and do some real help.
                            >
                            I do. Every day. But some people are just too think skulled to accept it.
                            >
                            >>>The whole question only makes sense with a server application.
                            >>
                            >>Not at all. Something on the server that is completely independent
                            >>(i.e. a cron job that runs every 10 seconds) can replace the HTML pages
                            >>between requests from the browser.
                            >
                            >
                            :-))
                            >
                            >
                            >>>HTML cannot generate HTTP-headers like the header()-function does.
                            >>>You don't know what you're talking about.
                            >>
                            >>Actually, I do. Apache/IIS can and does generate EXACTLY the same type
                            >>of headers as PHP does.
                            >
                            >
                            Yes, of course, but it is not directed by the HTML code.
                            And HTML code is what a HTML newsgroup is about.
                            >
                            Actually, it is. But you wouldn't understand that.
                            >
                            >>So much for trying to help a complete idiot.
                            >
                            >
                            So you learned something in the end. Fine.
                            >
                            Yea, I learned to dump you in the bozo bin. So long, bozo.

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

                            Comment

                            • ctiggerf

                              #15
                              Re: Preventing Browser-caching between Frames

                              Hmm .. I don't think your problem is the caching at all. But you
                              didn't supply any code to us so we could actually see it for ourselves.
                              But curious as I was, I put together a simple example that would show
                              how someone might accomplish this. Granted there may be much better
                              ways to accomplish this ... but:


                              frames.html
                              ---
                              <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
                              "http://www.w3.org/TR/html4/frameset.dtd">
                              <HTML>
                              <HEAD><TITLE>PH P Frame Example</TITLE></HEAD>
                              <FRAMESET cols="20%, 80%">
                              <FRAME src="links.html " name="links_fra me">
                              <FRAME src="detail.php " name="details_f rame">
                              </FRAMESET>
                              </HTML>
                              ---


                              links.html:
                              ---
                              <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                              "http://www.w3.org/TR/html4/loose.dtd">
                              <html>
                              <body>

                              - <a href="detail.ph p?id=1" target="details _frame">Row 1</a><br>
                              - <a href="detail.ph p?id=2" target="details _frame">Row 2</a><br>
                              - <a href="detail.ph p?id=3" target="details _frame">Row 3</a><br>
                              - <a href="detail.ph p?id=4" target="details _frame">Row 4</a><br>
                              - <a href="detail.ph p?id=5" target="details _frame">Row 5</a><br>
                              - <a href="detail.ph p?id=11" target="details _frame">Row 11</a><br>
                              - <a href="detail.ph p?id=12" target="details _frame">Row 12</a><br>
                              - <a href="detail.ph p?id=13" target="details _frame">Row 13</a><br>
                              - <a href="detail.ph p?id=14" target="details _frame">Row 14</a><br>
                              - <a href="detail.ph p?id=15" target="details _frame">Row 15</a>

                              </body>
                              </html>
                              ---


                              detail.php:
                              ---
                              <?php
                              //need a session to store which ones are already highlighted
                              session_start() ;
                              $set=$_SESSION['set'];

                              //see if anything was given to highlight/de-highlight
                              if(isset($_GET['id'])) {
                              //see if the id is already set
                              $pos = strpos($set, ':'.$_GET['id'].':');
                              if($pos === false) {
                              //not in the string so put it there
                              $set .= ':'.$_GET['id'].':';
                              } else {
                              //in the string so remove it
                              $set = str_replace(':' .$_GET['id'].':',"",$set);
                              }

                              //now update the session
                              $_SESSION['set']=$set;
                              }
                              ?>

                              <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                              "http://www.w3.org/TR/html4/loose.dtd">
                              <html>
                              <body>

                              <style type="text/css">
                              .h { background-color:#CCCCFF; }
                              </style>

                              <table border="1" cellpadding="3" cellspacing="0" >
                              <tr<?php echo strpos($set, ':1:') !== false ? " class='h'" : '';
                              ?>><td>Row1</td><td>value1</td></tr>
                              <tr<?php echo strpos($set, ':2:') !== false ? " class='h'" : '';
                              ?>><td>Row2</td><td>value2</td></tr>
                              <tr<?php echo strpos($set, ':3:') !== false ? " class='h'" : '';
                              ?>><td>Row3</td><td>value3</td></tr>
                              <tr<?php echo strpos($set, ':4:') !== false ? " class='h'" : '';
                              ?>><td>Row4</td><td>value4</td></tr>
                              <tr<?php echo strpos($set, ':5:') !== false ? " class='h'" : '';
                              ?>><td>Row5</td><td>value5</td></tr>
                              <tr<?php echo strpos($set, ':11:') !== false ? " class='h'" : '';
                              ?>><td>Row11</td><td>value11</td></tr>
                              <tr<?php echo strpos($set, ':12:') !== false ? " class='h'" : '';
                              ?>><td>Row12</td><td>value12</td></tr>
                              <tr<?php echo strpos($set, ':13:') !== false ? " class='h'" : '';
                              ?>><td>Row13</td><td>value13</td></tr>
                              <tr<?php echo strpos($set, ':14:') !== false ? " class='h'" : '';
                              ?>><td>Row14</td><td>value14</td></tr>
                              <tr<?php echo strpos($set, ':15:') !== false ? " class='h'" : '';
                              ?>><td>Row15</td><td>value15</td></tr>
                              </table>

                              </body>
                              </html>
                              ---


                              (This can be viewed at
                              http://www.eadexchange.com/test/frames/frames.html)

                              Seems to work fine for me and I don't see any caching issues at all.

                              So perhaps if you post some code, we can see what you have going on,
                              and then we may be able to help you. Generally you should always come
                              up with a simple example that highlights your problem. Because from
                              just reading your post, (I hate to say it) it doesn't look like a php
                              problem. Unless your script is jacked, in which case we would need to
                              see the code.

                              Another reason that making a simple example is a good idea: I can't
                              remember how many times in making a simple example, I've solved my
                              problem. Also people don't have to try and guess what's going on.

                              One problem you might want to look at is where you are starting your
                              session (if you're using one, which we wouldn't have to guess if you
                              supplied example code). It needs to be the first line of code you
                              execute and come before any html is printed out. In other words you
                              can't to this:


                              <html><head>
                              <?php session_start() ; ?>
                              .....

                              Comment

                              Working...