How can I have a public function to run all my PHP cURL requests? -


i have basic restful api setup using curl requests.

at moment, attempting split out functions have 1 function runs requests.

for example, have following can called localhost/api/getuserdata

private function getuserdata() {      $url = 'localhost/api/users/';      runapicall($url); } 

that function goes on pass url runapicall(), following:

function runapicall($url) {       $ch = curl_init();      curl_setopt($ch, curlopt_url, $url);      curl_setopt($ch, curlopt_returntransfer, true);      curl_setopt($ch, curlopt_cookie, 'phpsessid=' . $_cookie['phpsessid']);      $result = curl_exec($ch);      curl_close($ch);       $this->response($result, 200); } 

although, keep getting error in console of http://localhost/api/getuserdata 500 (internal server error)

the api working fine before split out.

edit:

if change getuserdata() function following, works fine:

private function getuserdata() {      $url = 'localhost/api/users/';       $ch = curl_init();      curl_setopt($ch, curlopt_url, $url);      curl_setopt($ch, curlopt_returntransfer, false);      curl_setopt($ch, curlopt_cookie, 'phpsessid=' . $_cookie['phpsessid']);       $result = curl_exec($ch);      $status = curl_getinfo($ch, curlinfo_http_code);      curl_close($ch);      $this->response($this->json($result), $status); } 

you have issue scope inside class.

private function getuserdata() {      $url = 'localhost/api/users/';      $this->runapicall($url); // call $this object's runappcall() function } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -