$_GET is empty when the url has variables

2019-02-24 07:03发布

I have a url that look like this reg.php?lang=no_NO&passkey=testand im trying to get the passkey variable, but it keeps showing up blank.

When I try print_r($_GET); it prints Array ( ) ?! How can this happen?

The site look something like this

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

thats it. I can't understand why $_GET shows up blank. It's been driving me crazy for a while now..

3条回答
在下西门庆
2楼-- · 2019-02-24 07:42

When I run into something that stumps me like this, I always take my script right down to basics. Try this at the very top of your script:

var_dump($_GET);
exit;

Then you can see if in fact it is getting the vars from the hook. If not, then there may be something deeper... like is PHP really running with Apache? If it works, start adding in other things until it stops again and you can start narrowing down the culprit.

查看更多
淡お忘
3楼-- · 2019-02-24 07:47

Make sure your php.ini file doesn't set max_input_vars to 0. I accidentally set mine to something else so adding anything to $_GET created a PHP warning.

查看更多
放我归山
4楼-- · 2019-02-24 07:48

Moving this into an answer from my comments above. Two reasons your GET params might be missing. Either you have mode rewrite set up that removes them or you are using a framework, such as CodeIgniter that moves them elsewhere.

In case you are using CodeIgniter you can re-enable them with parse_str($_SERVER['QUERY_STRING'], $_GET);

查看更多
登录 后发表回答