Simple PHP Post-Redirect-Get code example

Simplest scenario:

<?php
if ($_POST) {
    //validate the input

   if (/* input is OK */) {
       // Execute code (such as database updates) here.
       // Redirect to this page.
       header( "Location: {$_SERVER['REQUEST_URI']}", true, 303 );
       exit();
    }
}
?>
<html>
<!-- here goes your HTML page with a form -->

Use REQUEST_URI. Do not use PHP_SELF as in most CMS systems and frameworks PHP_SELF would refer to /index.php.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)