首页 > 解决方案 > 如何在数组中设置 _GET

问题描述

$data2 = [
    'a' => '(!isset($_GET["a"])) ? "default" : htmlspecialchars($_GET["a"]);',
    'b' => '-(!isset($_GET["b"])) ? "default" : htmlspecialchars($_GET["b"]);',
    'c' => '(!isset($_GET["c"])) ? "default" : htmlspecialchars($_GET["c"]);',
    'd' => '(!isset($_GET["d"])) ? "default" : htmlspecialchars($_GET["d"]);',
];

curl_setopt($ch, CURLOPT_URL, "post request url");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data2));
curl_setopt($ch, CURLOPT_POST, 1);
$x = curl_exec($ch);
echo $x;

我在一个 php 中使用它,它通过以下请求调用一个 POST url 我将如何设置它,以便我可以编辑 1 个 php,例如放置 file.php?a=28.29.29&b=1232.231.121&c=2121&d= 8282832,它将为我填写帖子请求点,任何建议都会很棒

这是它通常手动的样子

$data2 = [
    'a' => '228.29.29',
    'b' => '-1232.231.121',
    'c' => '2121',
    'd' => '8282832',

];

标签: php

解决方案


根据您的问题,似乎存在语法错误,请将 $data 替换为以下代码,它应该可以正常工作。

$data2 = [
'a' => (!isset($_GET["a"])) ? "default" : htmlspecialchars($_GET["a"]),
'b' => (!isset($_GET["b"])) ? "default" : "-" .htmlspecialchars($_GET["b"]),
'c' => (!isset($_GET["c"])) ? "default" : htmlspecialchars($_GET["c"]),
'd' => (!isset($_GET["d"])) ? "default" : htmlspecialchars($_GET["d"]),
 ];

curl_setopt($ch, CURLOPT_URL, "post request url");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data2));
curl_setopt($ch, CURLOPT_POST, 1);
$x = curl_exec($ch);
echo $x;

推荐阅读