I have a page with an iframe with the following code. Basically I want it to act like a portal. Depending on which page they're visiting this from, they will see a different thing. When I tried to get the referrer with echo, it managed to fetch the parent URL but wouldn't redirect properly. Instead it would go to the default. I was wondering if this is something that is impossible to do?
$referrer = $_SERVER['HTTP_REFERER'];
switch($referrer) {
case "https://domain1.org":
header("Location: https://example.org/one");
break;
case "http://domain2.org");
header("Location: https://example.org/two");
break;
case "https://domain3.org":
header("Location: https://example.org/three");
break;
default:
header("Location: https://example.org");
}
EDIT 1: It would only redirect to the case header if I change it to the iframe URL, not the parent. Otherwise it would redirect to the default header.
EDIT 2: I've set up a testing environment here. The problem persists.
Adding a variable to the iframe URL so that it would detect the given variable rather than the parent URL. Not what I had in mind but works well as an alternative in my case.
<iframe src="https://example.org/redirect.php?variable=redirect1"></iframe>
$var = $_GET['variable'];
switch($var) {
case "redirect1":
header("Location: https://example.org/one");
break;
case "redirect2";
header("Location: https://example.org/two");
break;
case "redirect3":
header("Location: https://example.org/three");
break;
default:
header("Location: https://example.org");
}