Posts: 17
Threads: 4
Joined: May 2015
I installed commentics on mispicaderos.com, but I have also the same page (the same estructure, programing) in multiple domains: trovacamporella.com, cruisingmap.com, placeforlove.com
All of them are the same, bur different domain
The problem is that COMMENTICS only works in mispicaderos.com.
In all the rest domains, it is loaded, it shows post and form. (Even the BACKEND works!)
But if a user tries to post a message in those alternative domains, it does not do anything. No error and no working.
How to make it work for multidomains???
Thank you
Posts: 2,894
Threads: 59
Joined: Jun 2010
Commentics isn't a multidomain script. Where did you read that?
It needs an installation on each website.
Have
you completed
the interview?
Posts: 17
Threads: 4
Joined: May 2015
Hi, (sorry for delay on answering)
But the first version of Commentics worked prefectly on multidomain.
My website is just one, the only thing is the logo and some images change depending of the domain. So, there is just one place where I can installa commentics plugin..
In order to make it work, I have had to call it via iframe in the rest of domains. But it is not the best solution...
Regards,
Posts: 2,894
Threads: 59
Joined: Jun 2010
This will be because the earlier versions of Commentics didn't use ajax. With ajax, browsers by default implement a 'same-origin' policy meaning only ajax requests to the same domain work. To override this, you'll need to add a CORS directive to your site to allow cross-origin. In PHP you can do this using the header() function. It will need to be added at the beginning of your page, otherwise you'll get a 'headers already sent' error. Try to avoid allowing all domains using *. Instead just restrict it to the ones you want to allow. See below solution for this:
https://stackoverflow.com/a/7454204
Have
you completed
the interview?
Posts: 17
Threads: 4
Joined: May 2015
Ouch!!!
THANK YOU VERY MUCH!!!
I´ll try this
Posts: 17
Threads: 4
Joined: May 2015
uhmmm.
I know this is not commentics problem, but example code like this don´t work...
$allowedOrigins = [
"https://mispicaderos.com",
"https://trovacamporella.com"
];
if (in_array($_SERVER["HTTP_ORIGIN"], $allowedOrigins)) {
header("Access-Control-Allow-Origin: " . $_SERVER["HTTP_ORIGIN"]);
}
I get this message:
from origin 'https://trovacamporella.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Posts: 2,894
Threads: 59
Joined: Jun 2010
I think 'HTTP_ORIGIN' might be old. Try this:
PHP Code:
<?php
$allowedOrigins = [
"mispicaderos.com",
"trovacamporella.com"
];
if (in_array($_SERVER["SERVER_NAME"], $allowedOrigins)) {
header("Access-Control-Allow-Origin: https://" . $_SERVER["SERVER_NAME"]);
}
Have
you completed
the interview?