I have included this javascript on other domains:
var id = "<?php echo check_input($_GET['token']); ?>";
var querystring = "";
var lockerurl = "https://www.example.com/contentlocker/getlocker.php?" + 'id=' + encodeURIComponent(id) + '&r=' + encodeURIComponent(referrer) + querystring;
var iframecontents;
var old_display;
function optionstoquery(options) {
var query = "";
if (options.mt) query += "&mt=" + encodeURIComponent(options.mt);
if (options.dt) query += "&dt=" + encodeURIComponent(options.dt);
if (options.dd) query += "&dd=" + encodeURIComponent(options.dd);
if (options.md) query += "&md=" + encodeURIComponent(options.md);
return query;
}
function og_load(options) {
if (options) lockerurl += optionstoquery(options);
//preload
var xhr = new XMLHttpRequest();
xhr.open('GET', lockerurl, true);
xhr.onreadystatechange = function() {
if (this.readyState!==4) return;
if (this.status!==200) {
iframecontents = false;
return;
}
iframecontents = this.responseText;
};
xhr.send();
ogEditBody();
}
Console it show me:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading
the remote resource at
https://www.example.com/contentlocker/getlocker.php?id=3e066b64a78214a17620b5521b6d3ec4&r=aHR0cDovL2NwYWh1Yi51cy9yb29zdGVyMi5odG1s.
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
getlocker.php contains some php and html code!
I using Plesk as webserver and I have tried by adding in getlocker.php:
header('Access-Control-Allow-Origin: *');
But still not working!
3
Answers
The CORS header has to be sent in the main page request so if you just set it when you send an embedded scrip that is not enough.
Is this the first line in your PHP file?
Also, try sending
crossDomain: true
in your AJAX call or HTTPRequest.From the server side, on Linux server, you can set up the required header in web server configuration:
For source domain
example.com
in Plesk go toDomains > example.com > Apache and nginx settings
and add the following directives inAdditional directives for HTTP
andAdditional directives for HTTPS
:Alternatively, in this case,
.htaccess
file with the following content can be used:If Nginx is enabled and static content needed to be displayed, use the following directive in
Additional nginx directives
field without Apache directives: