Ok, I dont know how I solved the problem but I am guessing like the comment above said the header was being cache.
I am restarting the ssl with cloudflare, because it loves to cache everything.
Now in order to make it work I have to remove these two things from the javascript.
headers: {"X-My-Custom-Header": "some value"},
and
contentType: "application/json",
from all my ajax calls.
as I was mentioning the wild card, that I was using for only testing purposes, just to see if it was my dynamic php code that the issue. It was not, thankfully.
function cors() {
$domain = ltrim($_SERVER['HTTP_HOST'], "api.");
$origin = $_SERVER['HTTP_ORIGIN'];
if (preg_match("/^http[s]?[:]\/\/(w{3})?[.a-zA-Z ]*".$domain."$/i", $origin)) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
// may also be using PUT, PATCH, HEAD etc
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, DELETE");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
header('Content-Type: application/json');
header('Accept: application/json');
}
this is called at the beginning with cors(); not to cause any header and continent cross contamination.
Thank you for the advice, I needed ideas as to brainstorm on what could be the problem.
Update:
I thought that cloudflare was messing with the headers
https://support.cloudflare.com/hc/en-us/articles/200308847-Does-Cloudflare-support-Cross-origin-resource-sharing-CORS-
But looks like it might not be them even though purging the cache they had helped.
Then I got stuck on another problem, the POST and GET was working just fine, but not things like DELETE and OPTIONS.
So after dissecting and research I find the header() in PHP was not working.
It turns out to be
PHP headers not set with litespeed (but work with apache)
because of litespeed.
I have to have the headers on .htaccess as a temporary fix.
I mean PHP headers work but for some odd reason what I am seeing in the headers for postman program is not consistent in AJAX.