trapping repeatition

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

trapping repeatition

Post by harrisonad »

This is one of those refresh problem on browsers.
I have a single script that checks if it is already executed by user. It uses sessions.

Code: Select all

session_start();
if(!isset($_SESSION['executed'])){	
    /*
       bunch of codes here ...
    */	
    $_SESSION['executed'] = true;
}
Now, when the user will refresh this script after already executing it, it will not be excuted because of the if statement.
But from now on, every POST variables to be passed in this script will not work because the session is still alive.

Of course, you may say that I have to session_destroy() or unset() this session variable. But doing so, will disable my checking, making the script to be executed repeatedly on browser refresh.
Any idea on how or when to kill session without spoiling the checking?
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

dude either you are not talking english or i have some understanding problem :lol:

since you want to execute posted data again and again, i assume you want data replication or re-execution in your code :!:

however, if this is the case, why do you use session :?:

tell's us what you really want to do, so we can suggest some solutions 8)
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

dethron, you were not the only one who did not understand his question :)
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

sorry bros. let me explain it again.
This script submits to itself, and process queries according to the variables passed, let's say, a application form.
Now, I want to protect this script from being reexecuted by browser refresh using sessions.

But anyway, nice talking with you.
I would have to answer it myself.

This topic closed.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

8) dude you really rocks, i thought tailors have some problems with patching(sewing) their things :lol:
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

You will have to put some unique code into your form, like tokens (unique ids) and store it in your session or DB. If you find an already sent token, you know that the form has been send before.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

Thanks tim, you really know how to cheer me up. :cry: :wink: :lol:
Post Reply