Skip to content

Instantly share code, notes, and snippets.

@josephj
Created December 26, 2011 15:51
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 josephj/1521471 to your computer and use it in GitHub Desktop.
Save josephj/1521471 to your computer and use it in GitHub Desktop.
<?php
header("Access-Control-Allow-Origin: " . $_SERVER["HTTP_ORIGIN"]);
header("Access-Control-Allow-Methods: POST, GET");
header("Access-Control-Max-Age: 1");
header("Access-Control-Allow-Credentials: true");
$cookie = (isset($_COOKIE["cookie"]) && $_COOKIE["cookie"] !== "") ? $_COOKIE["cookie"] : NULL;
if ( ! $cookie)
{
$value = "from cookie." . rand(1,10000);
$expire = time() + 3600;
$domain = ".josephj.com";
header("Set-Cookie: cookie=$value; expires=$expire; domain=$domain");
}
echo "cookie={$cookie}";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment