简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM