Home php教程 php手册 PHP程序处理网页表单的GET和POST方法另外用法

PHP程序处理网页表单的GET和POST方法另外用法

Jun 21, 2016 am 09:01 AM
array method post temp true

有时候我们需要保留GET和POST参数在下一页或者其他用途上传递!
工作上的方便于是我写了这样的代码!
希望大家多多交流!


/*
程序设计: 林建炫(飘枫设计室)
made in 珠海 by 2007-03-24
QQ: 5818500
Email: linzhenxuan@163.com
请勿删除该版权信息
用途:保留和修改GET和POST参数
*/
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;//找到啦
$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;
}
?>

比如原来
GET: ?method=1&a=1&b=2
POST: y=2007&m=03
用了
=getplus('c','3')?>
之后显示
?method=1&a=1&b=2&y=2007&m=03&c=3
用了
=getplus('a','3','open')?>
之后显示
?method=1&b=2&y=2007&m=03&a=3
把a=3拖到最后面来了
我用=getplus('a','','open')?>来和javascript结合
上一页
自己感觉还是挺好的!
可能还有写Bug没发现吧!
希望大家多多提提!



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Teach you how to modify the temporary file location of Win7 Teach you how to modify the temporary file location of Win7 Jan 04, 2024 pm 11:25 PM

Teach you how to modify the temporary file location of Win7

A brief analysis of the POST method in PHP with parameters to jump to the page A brief analysis of the POST method in PHP with parameters to jump to the page Mar 23, 2023 am 09:15 AM

A brief analysis of the POST method in PHP with parameters to jump to the page

Solution to PHP Fatal error: Call to a member function fetch() Solution to PHP Fatal error: Call to a member function fetch() Jun 23, 2023 am 09:36 AM

Solution to PHP Fatal error: Call to a member function fetch()

What does temp mean in computer? What does temp mean in computer? Sep 29, 2021 pm 04:39 PM

What does temp mean in computer?

How to determine whether a post has been submitted in PHP How to determine whether a post has been submitted in PHP Mar 21, 2023 pm 07:12 PM

How to determine whether a post has been submitted in PHP

Internal error: Unable to create temporary directory [Resolved] Internal error: Unable to create temporary directory [Resolved] Apr 17, 2023 pm 03:04 PM

Internal error: Unable to create temporary directory [Resolved]

How to use python requests post How to use python requests post Apr 29, 2023 pm 04:52 PM

How to use python requests post

Sort array using Array.Sort function in C# Sort array using Array.Sort function in C# Nov 18, 2023 am 10:37 AM

Sort array using Array.Sort function in C#

See all articles