I have a website (eg. https://example.com) and it has (amongst others) a page called origpage.php
. But, I do not want the origpage.php
to open when a visitor who comes from a given domain (eg. http://example.net) want to open it. I want this visitor to be redirected to an other page, eg. otherpage.php
.
How can I do it?
(I think the "question-duplication" is not the case.)
Asked
Active
Viewed 50 times
-1

ZsG
- 73
- 1
- 8
-
You are probably looking for `$_SERVER['HTTP_REFERER']` and `parse_url` – HTMHell Dec 10 '17 at 10:16
-
Are you saying that when a person uses `https://example.com/origpage.php` then keep him on the page itself. But if he uses `http://example.net/origpage.php` then redirect him to `http://example.net/otherpage.php` ? – Mrigank Pawagi Dec 10 '17 at 10:18
-
No. If someone wants to open `https://example.com/origpage.php` then this page to be opened. Except, if someone comes from `http://example.net`. He has to be redirected to `https://example.com/otherpage.php` – ZsG Dec 10 '17 at 10:22
1 Answers
2
Try something like this:
if (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) {
$domain = str_ireplace('www.', '', parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST));
if ($domain == 'example.net') {
header('location: otherpage.php');
die();
}
}

HTMHell
- 5,761
- 5
- 37
- 79