[英]How to set GET POST and REQUEST strings dynamically
Okay So for awhile I have been attempting to set GET POST and REQUEST variables dynamically. 好了,一段时间以来,我一直在尝试动态设置GET POST和REQUEST变量。
I store the variables I want it to get or post or request inside an sql table. 我将我希望它获取或发布或请求的变量存储在sql表中。 each variable has it's own column.
每个变量都有自己的列。 In this same row it records the type I want it to try to use(GET,POST,REQUEST).
在同一行中,它记录了我希望它尝试使用的类型(GET,POST,REQUEST)。 I am telling you this so you see how I want to go about doing this.
我告诉你这件事,以便您了解我要如何去做。
Source 资源
$snmpbq=$os_DB->query("SELECT * FROM `spiders` WHERE site = '".$site_name."'") or die(mysql_error());
$num=$os_DB->num($snmpbq);
if($num == 1)
{
//get row as an associative array
$pb=$os_DB->fetch($snmpbq);
//data request type
$req_type = $pb['net_req_type'];
$a1 = $pb['a'];
$b1 = $pb['b'];
$c1 = $pb['c'];
$d1 = $pb['d'];
$e1 = $pb['e'];
$f1 = $pb['f'];
if($req_type == "get")
{
$a = $_GET[$a1];
$b = $_GET[$b1];
$c = $_GET[$c1];
$d = $_GET[$d1];
$e = $_GET[$e1];
$f = $_GET[$f1];
}
You can accomplish this in a much cleaner way by replacing the blocks with 1 block... rather then checking the request type. 您可以通过将块替换为1块,从而以一种更加简洁的方式来完成此操作...而不是检查请求类型。
If you remove all your blocks and replace with: 如果删除所有块并替换为:
$a = $_REQUEST[$a1];
$b = $_REQUEST[$b1];
$c = $_REQUEST[$c1];
$d = $_REQUEST[$d1];
$e = $_REQUEST[$e1];
$f = $_REQUEST[$f1];
As per the PHP Documents here 根据此处的PHP文档
The variables in $_REQUEST are provided to the script via the GET, POST, and COOKIE input mechanisms and therefore could be modified by the remote user and cannot be trusted. $ _REQUEST中的变量是通过GET,POST和COOKIE输入机制提供给脚本的,因此可以由远程用户修改,并且不能被信任。 The presence and order of variables listed in this array is defined according to the PHP variables_order configuration directive.
此数组中列出的变量的存在和顺序是根据PHP variables_order配置指令定义的。
Sounds like you need to use a variable variable . 听起来您需要使用变量variable 。
$result = 'someDataBaseQueryResult';
$$result = 'cool'; // now $someDataBaseQueryResult === 'cool'
You question is a bit confusing, but you could take this to the nth degree. 您的问题有点令人困惑,但是您可以将其提高到第n级。
Idea for the sample code: 示例代码的想法:
$sReq = $pb['net_req_type'];
foreach($pb as $key => $value) {
if($key == 'net_req_type')
continue;
${$key} = $_GET[$value];
}
It's a little late, and I'm a little drunk, but I think that may be close. 已经有点晚了,我有点喝醉了,但我认为可能已经接近了。 Haven't executed it though...
尚未执行...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.