var xhr = new XMLHttpRequest();
xhr.open("get", "https://site2.example.com/?g=x", true);
xhr.send();
fetch('https://site2.example.com/?g=x')
(in older browsers is not a ride)<img src="https://site2.example.com/?g=x">
this is also a GET request!file_get_contents('https://site2.com/?g='.$_GET['g']);
Find more questions by tags JavaScriptPHPjQueryWordPress
Here's what I added to site # 1 ( https://site1.com/ ):
Error in console when loading the site No. 1:
In the first case (via ajax): Failed to load https://site2.com/?g=1: Response to a preflight request doesn't pass the access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://site1.com' is therefore not allowed access.
In the second case (via xhr): Failed to load https://site2.com/?g=1: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://site1.com' is therefore not allowed access.
In the third case (using fetch): Uncaught (in promise) TypeError: Failed to fetch
What am I doing wrong? :)) - holly99 commented on June 10th 19 at 14:48
<?php header('Access-Control-Allow-Origin: *'); ?>
Method # 2 stopped giving the error in the console.
Checked through the code:
In the alert issued message from extensions like AdBlock, so I disabled it. But, unfortunately, the desired result for which all this was started, and has not received.
The fact is that when the user logs in at: https://site2.com?g=1 website records certain information, including cookies to the user. But after the injection at site 1, the user accesses a website 1, and even sign them on site 2 (without get parameters), site 2 still does not contain the cookies of the user and information about his visit in the statistics. How to achieve this if the regular transition at https://site2.com?g=1 all records? - holly99 commented on June 10th 19 at 14:51
I just tried to send a request
https://jsfiddle.net/bdzck5z9/
getting
No 'Access-Control-Allow-Origin' header is present
- Austen.Thompson53 commented on June 10th 19 at 14:54<?php header('Access-Control-Allow-Origin: *'); ?>
Introduced back. Try again, please. - holly99 commented on June 10th 19 at 14:57
https://toptrening.org/?ref=1 it gives an error 500 - Austen.Thompson53 commented on June 10th 19 at 15:00
Cookies are set:
https://oiz.by/wp-test/ - 2 cookies
https://oiz.by/wp-test/?ref=1 - 2 cookies
check on jsfiddle ( https://jsfiddle.net/bdzck5z9/ ) - also 2
Conclusion: js is not to blame, and functioning properly. - Austen.Thompson53 commented on June 10th 19 at 15:06
The second site with get parameter yields 4 cookies. I have deleted and 6 browsers I tried.
The same can not be such that I-4 e, and You have 2 :)
I'm with 3 devices tested, with 6 browsers, and even through proxies. Everywhere assigned to the desired cookies.
You do the same, as far as I can see - only session cookies are displayed.
If you check in Network tab, then going to site # 2 ?ref=1, selecting the tab ?ref=1, I get track. headers: Cookie:PHPSESSID=uogvpn3re5i8ivkoddpnaninb2; affwp_ref=1; affwp_ref_visit_id=-2; woocommerce_cart_hash=null
And in JSFiddle and the # 1 site only:
Set-Cookie:PHPSESSID=hho2504it6v2nfsacf9g771nl4; path=/
In the script settings I chose another method of tracking. And transfer the cookies will work!
Thank you so much for the help! I would be grateful if you try to visit the site and say, do You have cookies. Maybe this problem was solved by changing the method of tracking :) - holly99 commented on June 10th 19 at 15:15
And in jsfiddle: