This is a discussion on RE: [PHP] Keeping POST values when paging within the PHP General forums, part of the PHP Programming Forums category; Stut wrote: > > On 8 Jul 2008, at 21:09, Philip Thompson wrote: > >> On Jul 8, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Stut wrote:
> > On 8 Jul 2008, at 21:09, Philip Thompson wrote: > >> On Jul 8, 2008, at 2:42 PM, Thiago H. Pojda wrote: >> >>> On Tue, Jul 8, 2008 at 4:11 PM, Philip Thompson >>> <philthathril@gmail.com> wrote: >>> On Jul 8, 2008, at 12:32 PM, tedd wrote: >>> >>> At 4:18 PM +0100 7/8/08, Mayer, Jonathan wrote: >>> In the end I decided the simplest way of coding the functionality was >>> to do >>> something similar to what Eric said, and have some extra submit >>> buttons in >>> the form, called Next, Previous and Jump. When clicked, they each >>> submitted >>> the form again with a different flag set. Along with a session variable >>> storing the "current" page, I was able to code a reasonably neat >>> solution >>> deciding which results to show without having to rewrite any sections >>> of my >>> code. Because these submit buttons are tied to a form at the top of the >>> page, this has limited me to only having the navigational buttons at >>> the top >>> of the results table rather than at the bottom too, but that is >>> perfectly >>> fine in my situation. >>> >>> Jon: >>> >>> Actually, you don't need to use sessions, post, nor get to pass >>> variables between scripts. >>> >>> Here's an example: >>> >>> http://www.webbytedd.com/bb/tedd/index.php >>> >>> Of course, the smart ones on this list will figure it out pretty >>> quickly. >>> >>> I guess I'm not smart. =( If it's fairly obvious, then I'm not seeing >>> it... >>> >>> ~Phil >>> >>> Me neither. I'm guessing: either it's using a file to transfer vars >>> (cookie or server-written file), or... I don't know :P >>> >>> Regards, >>> Thiago >> >> Technically, SESSIONs and COOKIEs are just files as well, so I don't >> think it's a file. Oh oh oh! I know! He's using the Force! Did I get >> it right?! > > I've only had a quick look but as far as I can see it's keeping the vars > in a form, the form posts to index.php so I'm guessing index.php simply > includes the script you specify on the form. > > Not what I would call "pass[ing] variables between scripts" but that's > just semantics. > > -Stut > And how would you do that without accessing the $_POST var anyway? -Shawn |
|
|||
|
At 1:32 PM -0400 7/8/08, tedd wrote:
>Actually, you don't need to use sessions, post, nor get to pass >variables between scripts. > >Here's an example: > >http://www.webbytedd.com/bb/tedd/index.php > >Of course, the smart ones on this list will figure it out pretty quickly. > So, this code in the HTML page, at the stage just before the data is sent to the script of my choice, isn't using POST to pass the variable? <form method="post" action="index.php"> [snip] <input type='hidden' name='var2' value='hereWeGo'> [snip] </form> -Jim |
|
|||
|
>At 1:32 PM -0400 7/8/08, tedd wrote:
>>Actually, you don't need to use sessions, post, nor get to pass >>variables between scripts. >> >>Here's an example: >> >>http://www.webbytedd.com/bb/tedd/index.php >> >>Of course, the smart ones on this list will figure it out pretty quickly. >> > >So, this code in the HTML page, at the stage just before the data is >sent to the script of my choice, isn't using POST to pass the >variable? > ><form method="post" action="index.php"> >[snip] ><input type='hidden' name='var2' value='hereWeGo'> >[snip] ></form> > >-Jim Nope -- an explanation will be soon forthcoming. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|||
|
At 9:33 PM +0100 7/8/08, Stut wrote:
>I've only had a quick look but as far as I can see it's keeping the >vars in a form, the form posts to index.php so I'm guessing >index.php simply includes the script you specify on the form. > >Not what I would call "pass[ing] variables between scripts" but >that's just semantics. > >-Stut As I figured, the smart ones would figure it out pretty easily. In the old days when memory was tight we used to do something we called overlays. The process worked like this: 1. Your program would compute what it could with what memory was available. 2. Then the program would halt and the variables used to that point would be frozen in memory. 3. Then another program was loaded on top of the in situ program with spaces in the memory for the values. 4. Then the program would take off again using the new program and those variables. 5. The process would repeat as many times as necessary. Now, in this case I am not swapping scripts because of memory restraints, but rather bringing in new scripts to continue with another part of the program -- but, I'm exiting the old script. It turns out to be a very simple process and it works like this. Run your first script, populate whatever variables you need (including post, get, and such) and then figure out where you want your program to go (i.e., next phase). Instead of populating a bunch of sessions, or filling up a database with values, simply -- ob_clean(); include('theNextScript.php'); exit(); -- and bingo! TheNextScript.php will have all the variables your original script had and your old script will be no more. -Stut is technically right, it's not really passing variables but rather "overlaying" a new script on top of the old one. In any event, I find it a neat way to continue a script without having to resort to using sessions, or other such storage mechanisms, to "pass" variables to the new script. Try it -- it works neat. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|||
|
On Jul 8, 2008, at 4:19 PM, tedd wrote:
> At 9:33 PM +0100 7/8/08, Stut wrote: >> I've only had a quick look but as far as I can see it's keeping the >> vars in a form, the form posts to index.php so I'm guessing >> index.php simply includes the script you specify on the form. >> >> Not what I would call "pass[ing] variables between scripts" but >> that's just semantics. >> >> -Stut > > As I figured, the smart ones would figure it out pretty easily. > > In the old days when memory was tight we used to do something we > called overlays. > > The process worked like this: > > 1. Your program would compute what it could with what memory was > available. > > 2. Then the program would halt and the variables used to that point > would be frozen in memory. > > 3. Then another program was loaded on top of the in situ program > with spaces in the memory for the values. > > 4. Then the program would take off again using the new program and > those variables. > > 5. The process would repeat as many times as necessary. > > Now, in this case I am not swapping scripts because of memory > restraints, but rather bringing in new scripts to continue with > another part of the program -- but, I'm exiting the old script. > > It turns out to be a very simple process and it works like this. > > Run your first script, populate whatever variables you need > (including post, get, and such) and then figure out where you want > your program to go (i.e., next phase). Instead of populating a bunch > of sessions, or filling up a database with values, simply -- > > ob_clean(); > include('theNextScript.php'); > exit(); > > -- and bingo! TheNextScript.php will have all the variables your > original script had and your old script will be no more. > > -Stut is technically right, it's not really passing variables but > rather "overlaying" a new script on top of the old one. > > In any event, I find it a neat way to continue a script without > having to resort to using sessions, or other such storage > mechanisms, to "pass" variables to the new script. > > Try it -- it works neat. > > Cheers, > > tedd Clever, clever. I actually did something along these lines in the app I'm currently working on. I had a form, submitted it (to the same page), it did it's processing and continued on that page w/o forwarding. Mine did, however, use POST. For example, <?php if (isset ($_POST['confirm'])) { // Do stuff here // After doing stuff here, you could have a // header() redirect } // Now just continue onto the page ?> <form action="thispage.php">...</form> The downfall for doing it this way, w/o redirecting upon submit, is not being able to *refresh* w/o being prompted with submitting the form again. Now that I think about it... this has nothing to do with what you did! Ha! Ok, I'm going home - I'm tired. ~Phil |