People come to the site number 1 link: site1.com/?g=X, where X is any number. I need to pass this get parameter (g = X) to site # 2 (site2.com) at the time of loading the first site. I have access to both sites and can embed any scripts into them.

As I understand it, to solve this problem, site # 1 should do one of these things:

  • send a request to the site №2.
  • go to site number 2.
  • open / close the site in a new small window (not comme il faut, and as I understand it, the browser can block pop-up windows.)
  • use some kind of API.

Which option is best and how to implement it? I'm noob, so I will be grateful to any code :)

  • via frontend - XMLHttpRequest (Fetch API), on the backend - depending on the situation - Daniel Khoroshko

2 answers 2

The first option is the best. There is no need for api jquery. Make Ajax request asynchronous and that's it. I will not give an example because they are full of the Internet. I hope helped

Read:
AJAX Example

On the server, you receive the data as usual.

  • Well, at least one example for decency would lead) - Alexander Belinsky
  • @ Alexander Belinsky Changed the answer - user8978194
  • Yes, and jquery is not needed - Daniel Khoroshko
  • with jquery will be easier - user8978194

first version on pure php

file_get_contents('http://site.ru/index.php?param='.$_GET['param']);