代码之家  ›  专栏  ›  技术社区  ›  ganjan

当url有变量时,$\u GET为空

  •  4
  • ganjan  · 技术社区  · 14 年前

    reg.php?lang=no_NO&passkey=test 我试图得到passkey变量,但它一直显示为空。

    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>
    

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

    3 回复  |  直到 14 年前
        1
  •  7
  •   Chuck Burgess    14 年前

    当我遇到像这样让我难堪的事情时,我总是把我的剧本带到最基本的地方。在脚本的最顶端尝试以下操作:

    var_dump($_GET);
    exit;
    

        2
  •  5
  •   Matt Williamson    14 年前

    如果您正在使用CodeIgniter,您可以使用 parse_str($_SERVER['QUERY_STRING'], $_GET);

        3
  •  1
  •   user1345650    10 年前

    确保php.ini文件未设置 max_input_vars 0 . 我不小心将我的设置为其他内容,因此在$中添加任何内容都会创建一个PHP警告。

        4
  •  0
  •   Mugasho Lincoln    4 年前

    我也遇到了类似的问题 $_GET[] 空的。主要是因为某个地方的服务器问题,我不得不生成自己的 $GET $_SERVER['HTTP_REFERER']

    //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'