SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Hybrid View

  1. #1
    Extremists Beware! Rockrz's Avatar
    Join Date
    Mar 2001
    Location
    In God's Country!
    Posts
    1,317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to block Access by IP Number

    I was saw somewhere how to block access to a web site according to someone's IP number.

    I have a guy who is harrasing me since we are competitors and I don't want him accessing my business site from his home, or his work.

    I have his IP numbers from both locations through e-mails he has sent me in the past.

    Anybody know how to do this? If I remember correctly, I think it was a javascrip that had the ability to accomplish this.

  2. #2
    SitePoint Evangelist
    Join Date
    Nov 2002
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can redirect the user on server-side depending on his IP. If you use ASP it should be something like this:

    [VBS]

    If Request.ServerVariables("REMOTE_ADDR") = "234.234.234.234" Then
    Response.Redirect "http://different-site.com"
    End If

    [/VBS]

    Keep in mind that your friend may have different IP every time he is online

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A PHP equivalent to asp-hosting's example would be
    PHP Code:
    if ($_SERVER['REMOTE_ADDR'] == '234.234.234.234')
        
    header("Location: dont_bug_me_dude.htm"); 
    Or, you can do it with a combination of javascript and SSI (means all your pages have to be .shtml)
    Code:
    var ip = "<!--#echo var="REMOTE_ADDR"-->";
    if (ip == '234.234.234.234' || ip == '234.234.234.235')
        window.location.replace("dont_bug_me_dude.htm");
    This disadvantage to this method, of course, is that it can be circumvented simply by turning off javascript. Of course, you can consequently redirect all non-javascript surfers to another page
    Code:
    <noscript>
    <meta http-equiv="refresh" content="0;URL=turn_on_javascript_you_fool.htm" />
    </noscript>
    Last edited by beetle; Nov 13, 2002 at 10:12.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  4. #4
    Extremists Beware! Rockrz's Avatar
    Join Date
    Mar 2001
    Location
    In God's Country!
    Posts
    1,317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys!

    I would have replied earlier, but for some reason I didn't get notification from the board that someone had replied.

    This individual is on Road Runner. Do they have a different IP number everytime they "go online", since it's a connection that's always on?

    I don't know much about it, but it seems that a high speed connection wouldn't be like a regular dial-up in terms of the IP number possibly being different everytime they go on the net.

    I'm just doing straight html, so maybe I'd better stick with javascript.
    Last edited by Rockrz; Nov 15, 2002 at 16:42.

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well acutally, most users with a basic Roadrunner account (or any cable connection) are assigned an IP from a DHCP server. This means that they obtain a non-used IP address everytime they connect. Yes, cable connections are 'always on', but only while the computer is on. I haven't personally rebooted in weeks, so I have had the same IP since then. However, if I reboot, I may get a different IP, I also may get the same. Now, most ISPs that offer broadband will give you a static IP if you pay a bit more than the basic package.

    Now, one thing that typically stays constant is the user's MAC address (well, it DOES stay constant, but some routers can spoof other MAC addresses), but I'm not sure if those can be read server-side. I'll research it a bit.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    Extremists Beware! Rockrz's Avatar
    Join Date
    Mar 2001
    Location
    In God's Country!
    Posts
    1,317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I'd appreciate any help I could get on this.

    This guy is a real pain.
    I know even if I could block his IP, he could go to another machine with a different connect (like at a friend's house) and get right on).

    I just thought I'd try & redirect his IP number to a generic page that looks like something your webhost would put up if you were overdue on your hosting bill.

    Then he'd think I was having a hard time paying my bills, which is what I want him to think (actually, I just want him to keep his nose out of my business)

  7. #7
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    You could go really hardcore and block his whole ISP by blocking the IP 234.234.*.*

    That could be a little drastic but I know someone who blocked an entire ISP from an IRC channel because 1 person was being a real turd.

  8. #8
    Extremists Beware! Rockrz's Avatar
    Join Date
    Mar 2001
    Location
    In God's Country!
    Posts
    1,317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm still unclear of the exact javascript code to use in order to block someone's IP address.

  9. #9
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Rockrz
    I'm still unclear of the exact javascript code to use in order to block someone's IP address.
    Re-read my first post
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  10. #10
    Extremists Beware! Rockrz's Avatar
    Join Date
    Mar 2001
    Location
    In God's Country!
    Posts
    1,317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I did.

    I don't know anything about php, so all I have to use is:

    if ($_SERVER['REMOTE_ADDR'] == '234.234.234.234')
    header("Location: dont_bug_me_dude.htm");

    Is that in the HEAD of my page?
    And nothing else is needed around it?

    _________________________________________


    I can't use:

    var ip = "<!--#echo var="REMOTE_ADDR"-->";
    if (ip == '234.234.234.234' || ip == '234.234.234.235')
    window.location.replace("dont_bug_me_dude.htm");

    because all my pages are straight HTML

    I saw a straight javascript once, but didn't save it.
    I should have because it was a simple script placed in the HEAD of a webpage.

    I'll go back & serach some of the script resource sites I have booked marked again....

    Thanks!

  11. #11
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Rockrz
    Is that in the HEAD of my page?
    And nothing else is needed around it?
    No! PHP is an HTML Pre-Processor (in fact, that's how PHP got it's name, recursive for Hypertext Pre-Processor). In otherwords, when a user requests a PHP page, it churns and chunks and does it's thing and returns HTML to the browser. Your ISP needs to have PHP installed on their server for you to use it. Find out if they do first.

    The SSI method doesn't require any HTML changes, but just an extension change to all your files from .htm or .html to .shtml. Most servers should support SSI. Make a test.shtml and try it out...
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

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