-1

hi I am trying to use GET to send some json data. I tried using this way 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' ;
            }
        }
    }

The error is Message: Undefined variable: GET For the secret part.

XAF
  • 1,462
  • 1
  • 10
  • 20

2 Answers2

2

You have a lot of literal mistakes. You need to relook at your code and change $GET to $_GET.

For example here:

$name = $_GET['name'];
$secret = $GET['secret'];
Robert
  • 18,927
  • 5
  • 54
  • 81
2

Change $GET['secret'] to $_GET['secret'] (in both places you are using it)

M. Eriksson
  • 12,711
  • 4
  • 26
  • 38