im new in PHP, and I have a task to get a data from my client using an API.. but the thing is, can't understand this API even after researching and trying about this..
My client has given me details for the API
URL - http://222.126.31.19:8084/api/login
Username - admin123
Password - test123
those are just a dummy values.. my client also said value should be the token response from login api and prepended by the word "Bearer "
After doing a research.. I tried this codes but nothing appears on my browser.. any idea or suggestion that I can do..
function CallAPI($method, $url, $data = false)
{
$curl = curl_init();
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
// Optional Authentication:
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "admin123:test123");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
Do i need to put this on a button or something? Sorry If I'm asking here, It's been a day and I can't solve it.