Welcome Guest, Not a member yet? Register   Sign In
CI, JSON Output, file_get_contents and cURL issue
#1

[eluser]Unknown[/eluser]
Ok, please bear with me as I am going to try and explain the issue I am encountering as best as possible.

I have a method within a controller eg: http://local.demo.com/controller/method that is outputting JSON eg:

Code:
<?php

class Controller extends CI_Controller
{
  
  function method()
  {
  
   $json = array("meta"=>"cool");
  
   header('Content-Type: application/json');
   echo json_encode($json);
  
  }
    
}

If navigate to http://local.demo.com/controller/method I am able to view valid JSON with no issues. If I attempt to use file_get_contents or to cURL the URL in another .php file to decode the JSON it is returned as null.

Now if I use file_get_contents or cURL on something like http://local.demo.com and the default controller is "controller" and the same code exists in the index method it works. eg:

Code:
<?php

class Controller extends CI_Controller
{
  
  function index()
  {
  
   $json = array("meta"=>"cool");
  
   header('Content-Type: application/json');
   echo json_encode($json);
  
  }
  
}

So, is the default controller and index method somehow making it not possible to access the desired controller and method via file_get_contents or cURL. Hopefully this makes sense. Thanks for any input.




Theme © iAndrew 2016 - Forum software by © MyBB