Add the link of the 'from' domain to your basedomain link like this:
<a href="http://basedomain.com?from=domain1.com">
Optional you can add some security to your link to verify that the 'from' part isn't altered, using HMAC. Or match the 'from' value at you base domain against a whitelist that contain the possible 'from' URL's.
Hope this helps?
EDIT
Easiest way for now is to go with the whitelist variant. To do that, you have to do the following steps:
- Create a link to the basedomain from each (sub)domain like i've done above.
- The 'from' var contains the identifier of the current domain, for example the name (domain1.com)
-
Build an array on your basedomain containing the valid enrties like this:
$validDomains = [
'domain1.com' => 'http://www.domain1.com/',
'domain2.com' => 'http://www.domain2.com/',
....
];
-
Building the back link on your base domain, start with checking the 'form' key against the validDomains. If the key exists, add the value of the validDomains as href link:
$linkForYourHref = null;
if (!empty($_GET['form']) && isset($validDomains[$_GET['form'])) {
$linkForYourHref = $validDomains[$_GET['form'];
}
//button code
if (!is_null($linkForYourHref)) {
//link to $linkForYourHref
}
An another options is to authenticate your 'from' part of the basedomain link by adding a hash to the URL like this:
<a href="http://basedomain.com?from=domain1.com&key=theHMACkey">
See Paragonie for more info about that