note 82452 added to language.variables.external
| From: | wayne at osu1 dot php dot net | Date: | Fri, 11 Apr 2008 11:52:16 +0000 |
| Subject: | note 82452 added to language.variables.external | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-138182@lists.php.net to get a copy of this message | ||
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;
}
}
?>
----
Server IP: 209.41.74.194
Probable Submitter: 207.235.61.213
----
Manual Page -- http://www.php.net/manual/en/language.variables.external.php
Edit -- https://master.php.net/note/edit/82452
Del: integrated -- https://master.php.net/note/delete/82452/integrated
Del: useless -- https://master.php.net/note/delete/82452/useless
Del: bad code -- https://master.php.net/note/delete/82452/bad+code
Del: spam -- https://master.php.net/note/delete/82452/spam
Del: non-english -- https://master.php.net/note/delete/82452/non-english
Del: in docs -- https://master.php.net/note/delete/82452/in+docs
Del: other reasons-- https://master.php.net/note/delete/82452
Reject -- https://master.php.net/note/reject/82452
Search -- https://master.php.net/manage/user-notes.php