IT13122256 Ranawaka R.A.S.M IT13122256 Ranawaka R.A.S.M - 1 year ago 188
PHP Question

angular send cookies from http request to php

so this question ask several time but still i could't figure this out. i'm sending http request from angular app to php service. and i need access the cookies i set from the browser. i know that to access cookies from php service i have to set the withCredentials in my http request. but then again wilcard error raised.

here is the http request

url : $scope.urlDomain+ "setting/getAll?skip=0&take=10&orderby=asc",
method :"POST",
headers : {
securityToken : "1124"
withCredentials: true

i had set the headers in my php file

header("Access-Control-Allow-Origin: * ");
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: PUT,POST, GET, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: origin, x-requested-with, content-type, securityToken");

this is the error

XMLHttpRequest cannot load http://localhost/services/getAll?skip=0&take=10&orderby=asc. Response to preflight request doesn't pass access control check: A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute

i stuck in this over day and still could't figure this out. thanks guys

Answer Source

You cant use header("Access-Control-Allow-Origin: * "); when you enable withCredentials, you have to specify a domain like this:

header("Access-Control-Allow-Origin: domain2");
header("Access-Control-Allow-Origin: domain3");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download