Tschallacka
Tschallacka

Reputation: 28722

Double page load how to prevent it?

I have the following if statement in PHP:

if(isset($_POST['approved']))
    {
    // do stuff
    }
else
    {
    // give the user an error message
    }

Now the problem is that AND the if is getting executed AND the else is getting executed.

Now i've tracked the problem to a double page load problem and and a post and get request are sent at the same time or something like that but executed in the same file.

Simply put, how do I prevent this so my users don't get shipped with error messages whilst everything was done allright?

Is there a way to configure PHP to only allow a one time execution?

Trying to think about this gives me serious headaches, as if I have a parralel universe where the opposite happens but it all comes back to this universe as both have happened...

Schrodingers cat but without the collapsed wave function.

Upvotes: 0

Views: 380

Answers (1)

DiMono
DiMono

Reputation: 3368

If the page is being loaded twice, then the problem is not with your php in this file, it's a problem with the file that calls it. Basically, it's loading twice because it's being requested twice. Don't try to stop the php file from executing, stop the second request from happening.

Upvotes: 2

Related Questions