Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    IP redirection on Apache server

    Hi, I am trying to accomplish the following:

    -- redirect various visitors to my website to other sites, based on their IP. As I want to exclude various classes of IP, how would this be done with PHP. So far I have the following:

    <?php
    $ipi = getenv("REMOTE_ADDR");
    if(eregi("111(.*)", $ipi) || eregi("222(.*)", $ipi))
    {
    echo "<META http-equiv='Refresh' content='0; url=welcome.html'>";
    }
    else
    {
    echo "<META http-equiv='Refresh' content='0; url=index2.html'>";
    }
    ?>

    In this case, welcome.html uses a redirect function to send people to somewhere.com.

    In the above case, the IPs of the form 111.xxx.xxx.xxx and 222.xxx.xxx.xxx are restricted.

    Anybody who can tell me how would I restrict 111.123.134.xxx and so on? This would restrict a very limited domain.

    Can I use the same function?

    THANKS!!!!

  • #2
    New Coder
    Join Date
    May 2004
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's probably easier to use a .htaccess-file for that:

    put this in it:
    Code:
    order allow,deny
    deny from 123.45.6.7
    deny from 123.34.5.
    deny from 123.
    deny from .codingforums.com
    allow from all
    needles to say that you should change the ip-blocks and domain.
    you can block users per domain or IP. I just put some possible values in it.

    maybe this could help too:
    (original: http://originalsinner.net/pig/tutorials/htaccess.htm )
    This is a script that will redirect IP's that you don't want viewing your site. (I set up an account on geocities for this script so that people would know they had been blocked and why.)


    RewriteEngine on
    RewriteCond %{REMOTE_ADDR} 00\.00\.00\.
    RewriteRule .* http://www.youralternativedirectory/yourwarningpage.htm [R]

    *Remember to change the IP address (00\.00\.00\.) to whatever IP you are blocking, but keep it in the same format! Also, change the URL to the directory (not a directory on your site) that you can link to to warn them that they have been blocked.

    Johan

  • #3
    New to the CF scene
    Join Date
    May 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot!!! I will look into it...However, I might not be able to do it like this since I get my hosting from an external server, and I am not sure if I have access to the Apache configuration specifically.

    In the meantime, would there be a PHP solution for this?

    THANKS!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •