ionic app cannot connect to php app due to cors
<p>Below is my ionic code. An angular service making an API call.</p>

<pre><code> var login = function (user)
    {
      return $q(function(resolve, reject)
      {
        $http.post(API_ENDPOINT.url + '/login',user)
          .then(function (result)
          {
            if(result.data.success)
            {
              resolve(result.data.msg);
            }
            else
            {
              reject(result.data.msg);
            }
          });
      });
    };
</code></pre>

<p>This below is the code on the php end.</p>

<pre><code>$app    =   new \Slim\Slim();
// Get request headers as associative array
$headers                = $app-&gt;request-&gt;headers;
$http_origin            = $headers['Origin'];
$allowed_http_origins   = array("http://localhost","http://localhost:80",
    "http://localhost:8080","http://localhost:63342","null",
    "http://localhost:8100","http://localhost:8888","http://localhost:8889");

if (in_array($http_origin, $allowed_http_origins)){  
    $app-&gt;response-&gt;headers-&gt;set('Access-Control-Allow-Origin',"$http_origin");
}

$app-&gt;response-&gt;headers-&gt;set('Access-Control-Allow-Methods','GET, PUT, POST, DELETE, OPTIONS');
$app-&gt;response-&gt;headers-&gt;set('Access-Control-Allow-Credentials','true');
$app-&gt;response-&gt;headers-&gt;set('Access-Control-Allow-Headers','*');
$app-&gt;response-&gt;headers-&gt;set('Access-Control-Allow-Origin',"$http_origin");


$app-&gt;post('/login/', 'Login' );
</code></pre>

<p>The app is having an issues with the CORS, it gives an error of Access-Control-Allow-Origins not present.</p>