使用isset不读取url中的变量

时间:2014-03-12 16:25:09

标签: php wordpress

我的地址是www.mysite.com/test-url?tx=test

if (isset($_GET['tx'])) {
    echo 'Success';

 }

然而,根本没有发生的事情,它根本就没有读到变量存在的事实

2 个答案:

答案 0 :(得分:0)

您的.htaccess文件中似乎正在使用mod_rewrite

所以,你在.htaccess

中会有类似的内容
RewriteRule ^([^/\.]+)?$ index.php?page=$1 [L]

您需要像这样添加QSA

RewriteRule ^([^/\.]+)?$ index.php?page=$1 [L,QSA]
                                             ^^^^

这告诉服务器追加查询字符串.. more info at apache.org

答案 1 :(得分:0)

从我在你写的评论中看到的,你提到你在WordPress上。

TBH,我不是Wordpress的人,因此我无法在更大的范围内提供帮助和排除故障,但请尝试添加额外的条件语句来匹配单词test。 GET。

以下内容在我的服务器上成功(不是Wordpress)。如果网址为test-url?tx=,则会失败,如果该网址为test-url?tx=testx,则也会失败,因此只有test-url?tx=test才会被视为成功。

<?php
if (isset($_GET['tx']) && $_GET['tx'] == test) {
    echo 'Success.';

 }

else {
echo "Sorry, the parameter is not set or is invalid.";
}

修改

Have a look在此this Q&A我找到了第一个来自的{{3}}。

我谷歌"if (isset($_GET not working with wordpress php"你肯定会在这里找到许多其他结果。