Need to redirect visitors based on their IP address

Posted on 2005-05-02
Last Modified: 2012-05-05
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?
Question by:sudama

    Accepted Solution

    if you place
    <IFRAME SRC="" TITLE="my Redirector">
    on the page which needs to redirect

    and redirect.html contains

    <script language="javascript" >
    function redir() {
"","_parent", "");
    <body onLoad="redir()">

    generated by SSI or php or whatever. It'll work

    Author Comment

    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.self)\n";
    echo " {\n";
    echo "\"\"\n";
    echo " }\n";
    echo " //-->\n";
    echo "</SCRIPT>";

    Author Comment

    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="" height="1" width="1"><iframe>

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
    Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
    In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
    In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now