I have developed a small webservice which will take user query and returns data as json response. Everything working fine. But I was wondering how to set and compare Authorization token from the client side as part of the curl header. This is my code to send request . Still I didn't set any validation thing on FetchData.php. I want to implement that on FetchData.php. How to implement that ?
$query = "select * from product_details where id = 2";
$query_params = array("query" => $query);
$url = "http://localhost/api/fetchData.php?" . http_build_query($query_params, '', "&");
$curl = curl_init();
$token = 'ABCD123456';
$header[] = 'Authorization: Token '.$token;
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
CURLOPT_HTTPGET=>1,
CURLOPT_FAILONERROR=> 1,
CURLOPT_RETURNTRANSFER=> true,
CURLOPT_HTTPHEADER=>$header
));
$resp = curl_exec($curl);
if($resp === false)
{
$responseJson = new stdClass();
$responseJson->status = "FAILED";
$responseJson->message = 'Send error: ' . curl_error($curl);
throw new Exception(curl_error($curl));
}
else{
$resp = curl_exec($curl);
}
In the above code I have added this authorization token . But acutually this was not set on server side I mean in fetchData.php
.
$token = 'ABCD123456';
$header[] = 'Authorization: Token '.$token;
so my question is how to set up this authorization token thing in fetchData.php
and validate the token which was from client side? Any help would be greatly appreciated.