2013-10-01 67 views
0

我正在开发wordpress的插件,根据用户通过Wordpress管理面板的偏好将$ _GET的参数记录在数据库中。下面的验证必须通过$ _GET,这是功能:

$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]; 

但不要返回任何值...

+3

'$ _GET ['$ url_before']!= $ _GET [$ url_before]',失去引号。 – Wrikken

+0

除了引用的东西,他确实说没有加引号的版本仍然没有返回 –

+0

你可能想检查整个'$ _GET'数组是什么,以防'$ url_before'设置不正确。 –

回答

1

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

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

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

的问题都解决了,感谢您的帮助。

0
if($_GET[$url_before] != ""){ 
    if($_GET[$url_before]=="nosupport"){ // note no "" here 
     // my function goes here... 
    } 
} 

在您的解决方案中,密钥被视为字符串,未评估变量。

0

你忘了取出'在第二个条件。

您写道:

 $_GET['$url_before'] 

我猜应该是:

 $_GET[$url_before]