• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 620
  • Last Modified:

Need to redirect visitors based on their IP address

We need to redirect certain visitors to our website based on their IP address(es).  Here's the catch:

Most of our website is a Yahoo store, which offers very limited functionality regarding server side includes, etc.  In fact I don't think any standard SSI calls such as <!--#echo var="REMOTE_ADDR" --> are supported.  It doesn't appear to parse PHP code either.

How can I redirect these users away from our pages to another site based on their IP address?  Can I embed an iframe or something similar on my pages that will load my redirect code from another server?  If so, how can I take over the main browser window and move it to another IP address or site?
0
sudama
Asked:
sudama
  • 2
1 Solution
 
djmajumdarCommented:
if you place
<IFRAME SRC="http://mydomain.com/redirect.html" TITLE="my Redirector">
...
</IFRAME>
on the page which needs to redirect


and redirect.html contains

<html>
<script language="javascript" >
function redir() {
      window.open("http://google.com","_parent", "");
}
</script>
<body onLoad="redir()">
blah1
</body>
</html>

generated by SSI or php or whatever. It'll work
0
 
sudamaAuthor Commented:
Not quite a complete answer, because your solution didn't include a way to determine the user's IP address.  I'll give you some points anyway though if I can.

What we ended up with is this freaky but effective hack, a mutant hybrid of PHP and javascript:

<?php
# Put offending IP addresses in here:
if($_SERVER['REMOTE_ADDR'] == "1.3.3.7" || $_SERVER['REMOTE_ADDR'] == "192.168.1.0" || $_SERVER['REMOTE_ADDR'] == "127.0.0.1")
{
echo "<SCRIPT language=\"JavaScript\">\n";
echo "<!--\n";
echo "if (window.top!=window.self)\n";
echo " {\n";
echo " window.top.location=\"http://www.othersite.com/\"\n";
echo " }\n";
echo " //-->\n";
echo "</SCRIPT>";
}
?>
0
 
sudamaAuthor Commented:
I should have mentioned that the above can be put on any server that supports PHP, named something like redirect.php

Add this code to hte page you want to redirect:

<iframe src="http://url.of.your.redir.script.com/redirect.php" height="1" width="1"><iframe>
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now