Created
August 26, 2016 20:54
-
-
Save phpdave/c1d4f04e4c0752c379572372f61edf17 to your computer and use it in GitHub Desktop.
XMLHttpRequest cannot load https://differentSubDomain.example.com/myPHPScript.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www1.example.com' is therefore not allowed access.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$subject = $_SERVER['HTTP_ORIGIN']; | |
$subdomain1 = 'www'; | |
$subdomain2 = 'www1'; | |
$pattern = '/http(s)?:\/\/('.$subdomain1.'\.)?('.$subdomain2.'\.)?(example.com)$/'; | |
$regexResult = preg_match($pattern, $subject); | |
if($regexResult) | |
{ | |
header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']); | |
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS'); | |
header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description'); | |
} | |
echo "Hi the browser has decided you're allowed to see this"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment