PHP – Redirect based on referrer or IP address

Redirect based on referrer or IP address

Referrer

— Code Example  —————————————-

<?php
$referrer = $_SERVER['HTTP_REFERER'];
if (preg_match("/Google.com/",$referrer)) {
      header('Location: http://www.google.com);
} elseif (preg_match("/yahoo.com/",$referrer)) {
      header('Location: http://www.yahoo.com);
} else {
      header('Location: http://www.connectiveinnovations.com);
};
?>
-----------------------------------
 IP Address
 — Code Example  ———————————–

<?php
$visitor = $_SERVER['REMOTE_ADDR'];
if (preg_match("/192.168.0.1/",$visitor)) {
} else {
};
?>
--------------------------------------------

This entry was posted in PHP. Bookmark the permalink.

Leave a Reply

Your email address will not be published.