如何在参数 $_GET 中使用变量?示例:($_GET[$my_var])

2022-01-04 00:00:00 variables parameters get php wordpress

我正在为 wordpress 开发一个插件,$ _GET 的参数根据用户的偏好通过 Wordpress 管理面板记录在数据库中.以下验证必须通过 $_GET,这是函数:

I'm developing a plugin for wordpress, the parameter of the $ _GET is recorded in the database according to the preference of the User via the Wordpress Admin Panel. The following validation has to be via the $ _GET, this is the function:

$db_url = get_option('my_get_url');
// returns the value of the database entered by User
// on this case return -->  page=nosupport

$url_explode = explode("=", $db_url);
$url_before = $url_explode[0]; // --> page
$url_after = $url_explode[1]; // --> nosupport

echo "Before: ".$url_before; // here are ok, return --> page
echo "After: ".$url_after; // here are ok, return --> nosupport

我的问题在这里:

// here $_GET no have any value, dont work on validate...
if($_GET[$url_before] != ""){ 
    if($_GET['$url_before']=="nosupport"){
        // my function goes here...
    }
}

我用于测试参数:

echo $_GET[$url_before];

但是不要返回任何值...

But dont return any value...

推荐答案

我发现了问题,我已经测试了所有这些选项,但一直不工作,问题是我正在测试主页内的功能我的网站,在主页 (mysite.com) 上没有获取参数 (?page=nossuport),所以当我在 GET 中使用变量或使用 echo $GET[$my_var 时总是返回空值] 测试..这是我的一个大粗心,永远不会工作......

I found the problem, i had already tested all of these options, but ever dont working, the problem was that I was testing the function inside the main page of my site, and on the main page (mysite.com) does not get the parameter (?page=nossuport), so always returning null values​​, when I used the variable in the GET or used the echo $GET[$my_var] to test.. It was a great carelessness of mine, would never work...

顺便说一下,这两个参数工作正常:

by the way, the two parameters works correctly:

$_GET[$url_before]
$_GET["$url_before"]

问题已解决,感谢帮助.

The Problem are solved, Thanks for help.

相关文章