note 82452 deleted from language.variables.external by danbrown

From: Date: Wed, 09 Mar 2011 14:35:28 +0000
Subject: note 82452 deleted from language.variables.external by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177694@lists.php.net to get a copy of this message
Note Submitter: wayne ---- I liked what Jonas Lindel�v suggested (below) and added a bit more to it: Removes the $_POST data and puts it in the session to avoid the F5 <refresh> msg that browsers give If $_POST data is received it is serialized to session and the page is redirected to itself without POST data. If $_GET data is received it converts arrays (from checkbox or select with multiple selections) to comma separated string and redirects the page to itself with the nicer GET string - instead of index.php?col%5B%5D=1&col%5B%5D=2&col%5B%5D=3&col%5B%5D=4 - we get index.php?col=1,2,3,4 <?php if($_POST or ($_GET and (!isset($_SESSION['skipnextget'])))) { //is there POST or GET data we should look at if($_GET) { //is there GET data? $newgetarr = array(); foreach($_GET as $key => $value) { if(is_array($value)) { $newvalue = implode(',',$value); //if it's an array, convert it to comma separated } else { $newvalue = $value; } $newgetarr[] = $key.'='.$newvalue; } $newget = implode('&',$newgetarr); $_SESSION['skipnextget'] = 1; } foreach($_POST as $key => $value) { $this[$key] = $value; } $_SESSION['postvars'] = serialize($this); //put POST in the session header("Location: http://" .$_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $newget); //reload page without POST data and shorter GET data exit(); } else { //after reloading we'll come right to this spot session_unregister('skipnextget'); if(isset($_SESSION['postvars'])) { $this = unserialize($_SESSION['postvars']); //load the POST variables from the session session_unregister('postvars'); //delete the session stuff return $this; } } ?>

« previous php.notes (#177694) next »