超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<gettypeintval>
Last updated: Fri, 22 Jun 2007

import_request_variables

(PHP 4 >= 4.1.0, PHP 5)

import_request_variables -- 将 GET/POST/Cookie 变量导入到全局作用域中

描述

bool import_request_variables ( string types [, string prefix])

将 GET/POST/Cookie 变量导入到全局作用域中。如果你禁止了 register_globals,但又想用到一些全局变量,那么此函数就很有用。

你可以使用 types 参数指定需要导入的变量。可以用字母‘G’、‘P’和‘C’分别表示 GET、POST 和 Cookie。这些字母不区分大小写,所以你可以使用‘g’、‘p’和‘c’的任何组合。POST 包含了通过 POST 方法上传的文件信息。注意这些字母的顺序,当使用“gp”时,POST 变量将使用相同的名字覆盖 GET 变量。任何 GPC 以外的字母都将被忽略。

prefix 参数作为变量名的前缀,置于所有被导入到全局作用域的变量之前。所以如果你有个名为“userid”的 GET 变量,同时提供了“pref_”作为前缀,那么你将获得一个名为 $pref_userid 的全局变量。

如果你对导入其它全局变量(例如 SERVER 变量)感兴趣,请考虑使用 extract()

注: 虽然 prefix 参数是可选的,但如果不指定前缀,或者指定一个空字符串作为前缀,你将获得一个 E_NOTICE 级别的错误。使用默认错误报告级别是不显示注意(Notice)级别的错误的。

<?php
// 此处将导入 GET 和 POST 变量
// 使用“rvar_”作为前缀
import_request_variables("gP", "rvar_");

print
$rvar_foo;
?>

参见 $_REQUESTregister_globals预定义变量extract()




add a note add a note User Contributed Notes
import_request_variables
camusatan@yahoo.NOSPAM.com
12-Nov-2002 12:52
On PHP 4.1.2, running on OpenBSD 3.1, I *think* (am not sure) that import_request_variables can mangle the contents of globals like $_REQUEST, $_POST, etc...here's my test.

print_r($_REQUEST);
import_request_variables("gpc","form_");
print_r($_REQUEST);

the second print_r crashes the server - for me.

I am not sure if this is because I have some form variables with underscores as the first character (_mode, _perform), or what, exactly, I'm just warning people that they might want to avoid using this function and instead just use the boring, unpleasant $_REQUEST['foo'] syntax, instead.

All I do know is that I re-wrote the thing to use the $_REQUEST syntax and it seemed to work. Caveat Lector.

<gettypeintval>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22