For some reason, I can't include a custom PHP $server variable inside of a header function. PHP doesn't acknowledge it's existence even though I can print it to console. Here are the steps I'm taking.
I have a header in my response which I fetch with
$domain = $_SERVER["HTTP_X_REQUESTED_DOMAIN"];
// print_r($domain);
// prints: stackoverflow.com
Next, I join the $domain variable with 'https://' and create a header.
$var = 'https://' . $domain;
header("Access-Control-Allow-Origin: " . $var);
However - I get a console error saying:
The 'Access-Control-Allow-Origin' header contains the invalid value 'https://'.
It's like the $domain variable is empty even though it's set and can be printed to console. If I change the domain variable to a string like 'stackoverflow.com' then everything works perfectly.
$domain = 'stackoverflow.com'.
I don't understand what could be the issue if both possibilities of the $domain variable return strings, are not empty, encoded with ASCII and print to screen if I run a print_r() function with them.
Any clues on what to troubleshoot?