I am new to rest API. I have this below function which returns HTML data I want this to be accessed from anywhere. I am using Zend with PHP 5.6 please give your suggestion.
fheader('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
if ($_SERVER['REQUEST_METHOD'] == "GET") {
$db = MysqliDb::getInstance();
//$sq = "ct-head";
$db->where("slug","ct-head");
$db->orderBy('version', 'desc');
$template = $db->getOne("tbl_templates");
$result = $template['modhtml'];
echo $result;
} else if ($_SERVER['REQUEST_METHOD'] == "POST") {
echo "POST";
} else {
http_response_code(405);
}
I have written something like this but if I access this from other system it is returning CORS error.
Any help would be appreciated.