title: webservices in PHP and json using codeigniter
body: <p>I am trying to create and use a webservice which will take input in json and provide output in same.
  But it is not able to provide the output correctly.</p>
  
  <pre><code>    function login() {
      $data = array(
          'login_id' =&gt; $this -&gt; input -&gt; post('login_id'),  
          'login_pwd' =&gt; md5($this -&gt; input -&gt; post('login_pwd')),
  
      );
      $data_string = json_encode($data);
      echo $data_string;
      $ch = curl_init(base_url().'admin_service/getUser');
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array(
         'Content-Type: application/json',
         'Content-Length: ' . strlen($data_string))
      );
  
      $result = curl_exec($ch);
      $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      $contenttype = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
      curl_close($ch);
  
      if ($result) {
          redirect(base_url() . '/success');
      } else {
          redirect(base_url(). 'relogin'); 
          }
      }
   }
  </code></pre>
  
  <p>Below code is for my webservice:</p>
  
  <pre><code>   function getUser_post() {
      $name = $this-&gt;post('login_id');
      $password = $this-&gt;post('login_pwd');
  
      $this -&gt; load -&gt; model('register_model');
      // calling the function in our login model
      $result = $this -&gt; register_model -&gt; get_user($name, $password);
  
      echo $result;
      return json_encode( array('result' =&gt; $result ) );
  
  }
  </code></pre>
  
  <p>Problem is: I am not gettign proper json response back in controller. All I am gettting is 1.</p>
  
  <p>I want to get additional information back from webservice. How can I send it back from webservice here.</p>
  
  <p>Any help appreciated.
  Thank you.</p>