Skip to content

Instantly share code, notes, and snippets.

@webarthur
Last active January 5, 2017 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webarthur/a5d48715a7931fb93a1a94ad932313e0 to your computer and use it in GitHub Desktop.
Save webarthur/a5d48715a7931fb93a1a94ad932313e0 to your computer and use it in GitHub Desktop.
Ajax subdomain CORS
// ajax
var xhr = new XMLHttpRequest();
xhr.open(method, url, true);
xhr.withCredentials = true;
[...]
// htaccess
SetEnvIf Origin "http(s)?://(www\.)?(example.org)$" AccessControlAllowOrigin=$0
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
Header set Access-Control-Allow-Credentials true
// PHP
ini_set('session.cookie_domain', '.example.org' );
session_name("domain");
session_set_cookie_params(0, '/', '.example.org');
session_start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment