Sometimes we need to retain GET and POST parameters to pass on the next page or other purposes!
For convenience at work, I wrote this code!
I hope you can communicate more!
<?
/*
Programming Design: Lin Jianxuan (Piaofeng Design Studio)
made in Zhuhai by 2007-03-24
QQ: 5818500
Email:[email protected]
Do not delete this copyright information Purpose: retain and modify GET and POST parameters
*/
function getplus($x='',$value='',$plus='close',$method='all'){
Global $_GET,$_POST;
$array = array();
if($method=='all'){
$array[] = $_GET;$array[] = $_POST;}
elseif($method=='get'){$array[] = $_GET;}
elseif($method=='post'){$array[] = $_POST;}
$a = $_GET;
$i = 1;
$true = 0;
foreach($array as $k => $a){
foreach($a as $b => $c){
if($b==$x){
$c = $value;
$true = 1; // Found it
$true2 = 1;
}
if($plus=='close'){
if($i==1){
$temp .= "?$b=$c";
}else{
$temp .= "&$b=$c";
}
}else{
if($i==1){
if($true2!=1){$temp .= "?$b=$c";}else{$temp.="?";unset($true2);}
}else{
if($true2!=1){$temp .= "&$b=$c";}else{unset($true2);}
}
}
$i++;
}
}
if($true==0){
if (strpos($temp,"?")>0 || strpos($temp,"=")>0){
$temp .= "&$x=$value";
}else{
$temp .= "?$x=$value";
}
}
elseif($true==1 && $plus!='close'){
if (strpos($temp,"?")>0 || strpos($temp,"=")>0){
$temp .= "&$x=$value";
}else{
$temp .= "?$x=$value";
}
}
return $temp;
}
?>
For example, it turns out
GET: ?method=1&a=1&b=2
POST: y=2007&m=03
Used
<?=getplus('c','3')?>
show later
?method=1&a=1&b=2&y=2007&m=03&c=3
Used
<?=getplus('a','3','open')?>
show later
?method=1&b=2&y=2007&m=03&a=3
After dragging a=3 to the end, I used <?=getplus('a','','open')?> to combine it with javascript to go to the previous page. I think it's pretty good!
Maybe there are still bugs that haven’t been discovered yet!
I hope everyone will mention it more!