当url有变量时,$ _GET为空

gan*_*jan 4 php variables post get global-variables

我有一个看起来像这样的网址,reg.php?lang=no_NO&passkey=test我试图获取密钥变量,但它一直显示为空白.

当我尝试print_r($_GET);打印Array ( )?!怎么会发生这种情况?

该网站看起来像这样

    <?php

        print_r($_GET); 

        include('..\libs\Smarty.class.php');
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Activate account</title>

(...html code.. )

$smarty = new Smarty;

//$smarty->force_compile = true;
$smarty->debugging = false;
$smarty->caching = false;
$smarty->cache_lifetime = 120;


// PHP gettext api
define('PROJECT_DIR', realpath('./'));

(... define gettext ... )

$passkey=$_GET['passkey'];

(...work with passkey ...)

$smarty->display('templates\site.tpl');

?>


</body>
</html>
Run Code Online (Sandbox Code Playgroud)

而已.我无法理解为什么$ _GET显示空白.它已经让我疯了一段时间了..

Chu*_*ess 6

当我遇到像这样困扰我的事情时,我总是把我的剧本归结为基础知识.在脚本的最顶部试试这个:

var_dump($_GET);
exit;
Run Code Online (Sandbox Code Playgroud)

然后你可以看到它是否实际上是从钩子获得变量.如果没有,那么可能会有更深层次的东西......就像PHP真的在运行Apache一样?如果它工作,开始添加其他东西,直到它再次停止,你可以开始缩小罪魁祸首.


Mat*_*son 5

将其转化为上述评论的答案.您的GET参数可能缺失的两个原因.你有模式重写设置删除它们或你正在使用框架,如CodeIgniter将它们移动到其他地方.

如果您使用的是CodeIgniter,可以使用它重新启用它们 parse_str($_SERVER['QUERY_STRING'], $_GET);

  • 打印出`$ _SERVER ['QUERY_STRING']`无论框架如何,都可能不是一个糟糕的起点. (5认同)