Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当url包含变量时,$\u GET为空_Php_Variables_Post_Get_Global Variables - Fatal编程技术网

Php 当url包含变量时,$\u GET为空

Php 当url包含变量时,$\u GET为空,php,variables,post,get,global-variables,Php,Variables,Post,Get,Global Variables,我有一个url,看起来像这个reg.php?lang=no\u no&passkey=test,我试图获取passkey变量,但它总是显示为空 当我尝试打印时($\u GET)它打印数组()?!这怎么会发生 网站看起来像这样 <?php print_r($_GET); include('..\libs\Smarty.class.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD

我有一个url,看起来像这个
reg.php?lang=no\u no&passkey=test
,我试图获取passkey变量,但它总是显示为空

当我尝试打印时($\u GET)它打印
数组()
?!这怎么会发生

网站看起来像这样

    <?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>

激活帐户
(…html代码…)
$smarty=新smarty;
//$smarty->force_compile=true;
$smarty->调试=false;
$smarty->caching=false;
$smarty->cache_life=120;
//PHP gettext api
定义('PROJECT_DIR',realpath('./');
(…定义gettext…)
$passkey=$_GET['passkey'];
(…使用密钥…)
$smarty->display('templates\site.tpl');
?>

就这样。我不明白为什么$\u GET显示为空白。有一段时间我都快疯了

当我遇到像这样让我难堪的事情时,我总是把我的脚本从最基本的部分开始。在脚本的最顶端尝试以下操作:

var_dump($_GET);
exit;

然后你可以看到它是否真的是从钩子上取下了变量。如果不是,那么可能还有更深层次的东西。。。比如PHP真的在Apache上运行吗?如果有效,开始添加其他内容,直到它再次停止,您可以开始缩小罪魁祸首的范围

将此转化为我上面评论的答案。可能缺少GET params的两个原因。或者您已经设置了删除它们的模式重写,或者您正在使用一个框架,例如将它们移动到其他位置的CodeIgniter


如果您正在使用CodeIgniter,您可以使用
parse_str($\u SERVER['QUERY_STRING'],$\u GET)重新启用它们

确保php.ini文件没有将
max\u input\u vars
设置为
0
。我不小心将我的设置为其他设置,因此向$\u GET添加任何内容都会创建一个PHP警告。

我遇到了类似的问题,即$\u GET[]empty。主要是因为某个地方的服务器问题,我不得不使用
$\u服务器['HTTP\u REFERER']
生成自己的
$GET

//url='http://example.com/?search=john&location=london';
$get=array();
$query=mb_split("&",parse_url($_SERVER['HTTP_REFERER'],PHP_URL_QUERY));
if(!empty($query)) foreach ($query as $qr){
    $vars=mb_split('=',$qr);
    $get[$vars[0]]=$vars[1];
}

var_dump($get['search']);
// output 'john'

您是否正在使用任何类型的url重写,或者reg.php是一个实际的文件?您是否碰巧使用了CodeIgniter或其他框架?有时他们会踩下$请求变量。@darma:即使reg.php是一个真正的文件,mod_rewrite也可能会丢失已写入的查询字符串improperly@zerkmsCI自动过滤器是一种安全措施_POST完全按照您的预期工作。您也可以使用_-GET,如果您愿意,只需显式启用它。@zerkms可防止一些错误做法。打印出
$\u服务器['QUERY\u STRING']
无论框架如何,实际上可能都不是一个好的起点。我想补充一点,对于某些框架/CMSE,原因可能是没有启用mod_rewrite。嗨,我得到的var dump是空数组。现在如何调试它。。。??我在URL中附加了值,这意味着GET请求中没有任何内容。请尝试$\u请求。你确定你没有发帖吗?