Home > Backend Development > PHP Tutorial > php 使用post,get的一种简洁方式_PHP

php 使用post,get的一种简洁方式_PHP

WBOY
Release: 2016-06-01 12:19:58
Original
817 people have browsed it

近来看到了一个巧妙地方法,原理是
$var_a ='var_b';
$$var_a ='test';
则echo $var_b;为'test'
因此可以这样处理
复制代码 代码如下:
foreach(array('_COOKIE', '_POST', '_GET') as $_request)
{
   foreach($$_request as $_key => $_value)
  {
    $_key{0} != '_' && $$_key = addslashes($_value);
  }
}

这样像test.php?name=name_in&pwd=pwd_in
你就可以直接用$name,$pwd
来引用客户端发送的数据。
注意:这里对客户发送的变量用addslashes()进行了过滤。

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template