Skip to content

Instantly share code, notes, and snippets.

@makotom
Last active December 11, 2015 22:58
Show Gist options
  • Save makotom/4673534 to your computer and use it in GitHub Desktop.
Save makotom/4673534 to your computer and use it in GitHub Desktop.
<?php
define("RDIR", (isset($_SERVER["HTTPS"]) ? "http://" : "https://") . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "?t");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: x-prototype-version,x-requested-with");
if(isset($_GET["r"])){
header("Location: " . RDIR);
exit();
}
if(isset($_GET["t"])){
echo "OK";
exit();
}
?>
<!doctype html>
<meta charset="UTF-8">
<title>1359554924</title>
<script>
(function(){
var xhr = function(url){
var x = new XMLHttpRequest();
x.open("GET", url, true);
x.setRequestHeader("X-Requested-With", "XMLHttpRequest");
x.onreadystatechange = function(){
if(x.readyState === 4){
alert(url + ": " + x.status.toString());
}
};
x.send(null);
};
// All shuold be 200?
xhr("?t");
xhr("<?php echo RDIR; ?>");
xhr("?r");
})();
</script>
@makotom
Copy link
Author

makotom commented Jan 30, 2013

CORS test. Requires HTTP/HTTPS dual-enabled httpd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment