【问题标题】:cannot get url data using GET request [duplicate]无法使用 GET 请求获取 url 数据 [重复]
【发布时间】:2017-01-05 12:17:29
【问题描述】:

您好,我正在尝试使用 GET 发送一些 json 数据。 我试过用这种方式 This is the url = localhost/index.php/getRequest?name=BestRate&secret=masnadsapi

public function getRequest(){
        $verb = $_SERVER['REQUEST_METHOD'];
        if($verb == 'GET'){
            if(isset($_GET['name']) && isset($GET['secret']) ){
               $name = $_GET['name'];
               $secret = $GET['secret'];

               if($name == 'BestRate' && $secret == 'masnadsapi'){
                   $foo = array(
                       'Todays Best Rate' => '5.6%'
                   );
                   $this->output->set_content_type('application/json');
                    $this->output->set_output(json_encode($foo));
               }else{
                   return;
               }

            }else{
                echo 'Masnad says  : no parameter giving' ;
            }
        }
    }

错误是消息:未定义的变量:GET 对于秘密部分。

【问题讨论】:

  • $GET['secret'] 更改为$_GET['secret'](在您使用它的两个地方)。
  • 哦,谢谢!!!我根本没有注意到!
  • @MagnusEriksson 请写下答案,以便我接受!非常感谢
  • 将其添加为答案。

标签: php json codeigniter url get


【解决方案1】:

$GET['secret'] 更改为$_GET['secret'](在您使用它的两个地方)

【讨论】:

    【解决方案2】:

    你有很多字面上的错误。您需要重新查看您的代码并将$GET 更改为$_GET

    例如这里:

    $name = $_GET['name'];
    $secret = $GET['secret'];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-19
      • 2021-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多