PHP equivilant to the javascript back

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nitinpatel1117
    New Member
    • Jun 2007
    • 111

    PHP equivilant to the javascript back

    Hi,

    What i'm trying to do, may not be possible. but i just wanted to know if there is a way of doing this.

    Basically what i am trying to achieve is to call the previous php script that was run before the currenttly executing script

    e.g.
    if page 'A.php' has a form in it, which has its data posted to page 'B.php'. I want page B.php to do some validation, on the posted data. and based on the results of this validation. I want page B.php to call up page A.php with all the posted variables that were posted to page B.php passed back to page A.php

    Thanks in advance.
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    In A.php, set <form> action to B.php. After validating use header() to redirect to A.php and to keep data use sessions.

    Make sure you do not create an ifinite loop.

    Comment

    • ak1dnar
      Recognized Expert Top Contributor
      • Jan 2007
      • 1584

      #3
      And If you like you can use One script to do the same job as A and B.
      Thanks!

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Originally posted by ajaxrand
        And If you like you can use One script to do the same job as A and B.
        Though this is generally not a good idea as it tends to break MVC, creates odd behavior when the User refreshes the page in his browser and encourages interweaving PHP and HTML code (which results in difficult-to-read code and misconceptions in how PHP works [e.g., "How do I call a PHP function using JavaScript?"]).

        Comment

        • kovik
          Recognized Expert Top Contributor
          • Jun 2007
          • 1044

          #5
          Seriously, you should just post to the same page. It simplifies life and actually makes sense. :P

          Comment

          • nitinpatel1117
            New Member
            • Jun 2007
            • 111

            #6
            Hi,

            What i'm actually trying to do is build a CAPTCHA for an online form.

            I thought about posting to the same page, but this page is already quite large with lots of programming code. Meaning that in future if another developer were to go through the code, they will have a pretty hard time tryin to understand whats already happening on the page.

            Also page B.php will not know which page sent it the posted data, so i can't hard-code that into the header(), i plan to have lots of script posting to this page (B.php) in other to check the captcha.


            But i think i'm going to have to post to the same page, becuase can't see any other alternative.
            Last edited by nitinpatel1117; Jul 9 '07, 08:49 AM. Reason: not detailed enough

            Comment

            • pbmods
              Recognized Expert Expert
              • Apr 2007
              • 5821

              #7
              Heya, nitinpatel.

              Originally posted by nitinpatel1117
              Also page B.php will not know which page sent it the posted data, so i can't hard-code that into the header(), i plan to have lots of script posting to this page (B.php) in other to check the captcha.
              Check out $_SERVER['HTTP_REFERER'].

              Comment

              • nitinpatel1117
                New Member
                • Jun 2007
                • 111

                #8
                Thats great phmods, i can't believe that i didn't find that server variable myself.

                Anyway, i assume that theres probably one for the posted variables as well, time for some more documentation reading i think

                Comment

                • pbmods
                  Recognized Expert Expert
                  • Apr 2007
                  • 5821

                  #9
                  Heya, nitinpatel.

                  One popular method for sharing data between two pages is to use the Session. Often, you'll see something like this at the top of some pages:
                  [code=php]
                  foreach($_POST as $key => $val)
                  $_SESSION[$key] = $val;
                  [/code]

                  There are better ways of doing it, but this code will do the job.

                  Add that to the top of page b (the one that does the data processing). Then, if there are errors, you can redirect the User to the form without having to pass variables back and forth.

                  Comment

                  Working...