• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 624
  • 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?
  • 2
1 Solution
if you place
<IFRAME SRC="http://mydomain.com/redirect.html" TITLE="my Redirector">
on the page which needs to redirect

and redirect.html contains

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

generated by SSI or php or whatever. It'll work
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:

# Put offending IP addresses in here:
if($_SERVER['REMOTE_ADDR'] == "" || $_SERVER['REMOTE_ADDR'] == "" || $_SERVER['REMOTE_ADDR'] == "")
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>";
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>
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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