Execute php with back button

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

    Execute php with back button

    Hi!!!!

    I need that when the user goes back to the last page with the "Back"
    button of the browser, the page executes the php code again.

    Is there any code to insert in php that implies a reload every time the
    page appears in the user browser??

    Best regards!!!

    Ezequiel

  • Lüpher Cypher

    #2
    Re: Execute php with back button

    zek2005 wrote:[color=blue]
    > I need that when the user goes back to the last page with the "Back"
    > button of the browser, the page executes the php code again.
    >
    > Is there any code to insert in php that implies a reload every time the
    > page appears in the user browser??
    >[/color]


    Simply disable caching:

    <?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

    session_start() ;
    if (!session_regis ter("var")) {
    session_registe r("var");
    $_SESSION["var"] = 1;
    } else {
    $_SESSION["var"]++;
    }

    echo $_SESSION["var"];

    ?>

    This will output 1 on first load,
    Go to some other site, then hit back, and it will output 2 :)


    luph

    Comment

    • Balazs Wellisch

      #3
      Re: Execute php with back button

      You could also try:

      <form action="<?php print $_SERVER['HTTP_REFERER']; ?>" method="get">
      <input type="submit" value="back">
      </form>

      Of course if the page was the result of a post than the method would have to
      be changed accordingly.

      Balazs
      [color=blue]
      >
      > Is there any code to insert in php that implies a reload every time the
      > page appears in the user browser??
      >[/color]


      Comment

      • Tim Roberts

        #4
        Re: Execute php with back button

        Lüpher Cypher <lupher.cypher@ verizon.net> wrote:[color=blue]
        >
        >Simply disable caching:
        >
        ><?php
        >
        >header("Cach e-Control: no-cache, must-revalidate"); // HTTP/1.1
        >header("Expire s: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past[/color]

        I've seen a number of different suggestions on disabling caching over the
        years, with variations that worked some places but not in others.

        Is this now the "canonical" recommended method of disabling caching of a
        web page? Does this really catch all the major browsers and proxies,
        including AOL's rather aggressive "accelerato r"?
        --
        - Tim Roberts, timr@probo.com
        Providenza & Boekelheide, Inc.

        Comment

        • Lüpher Cypher

          #5
          Re: Execute php with back button

          Tim Roberts wrote:[color=blue][color=green]
          >> <?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[/color]
          >
          > I've seen a number of different suggestions on disabling caching over the
          > years, with variations that worked some places but not in others.
          >
          > Is this now the "canonical" recommended method of disabling caching of a
          > web page? Does this really catch all the major browsers and proxies,
          > including AOL's rather aggressive "accelerato r"?[/color]

          Well, I'm not sure, as I haven't tested it on all browsers, but it
          should work fine since it is a http1.1 standard ;)


          luph

          Comment

          Working...