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 13 of 13

Thread: Banning IPs?

  1. #1
    New Coder
    Join Date
    May 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Banning IPs?

    Hi! Is there a way to ban IPs from coming to your site using HTML, Javascript, or CSS?

    I need a code where I can ban more then one IP at the same time and when the IP or Ips come to my site, it sends them to a "banned page" or different page (so they can't see mine!)!? I've tried different codes, and one even banned every IP instead of the ones I wanted it to ban !

    Does anyone know of a good IP banning code? Thanks!

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You can't do this with html,javascript, or css, what you can do is use .htaccess, here is a simple tutorial on how to do this, or if you want you can do it in php as well, another tutorial can be found here.

  • #3
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    You can do it with .htaccess and also if you want to ban certain IPs from one or two directories/files and if your server supports PHP, you can do it with that. I also know a way of doing it in ASP

  • #4
    New Coder
    Join Date
    May 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok

    How would I be able to put a PHP code on HTML? Something like this:

    Code:
    <script language="PHP" src=".php">
    </script>
    And please not a PHP code to put a PHP code on HTML! Thankz

  • #5
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    nooooooooo!

    You start a php script with:

    <?php

    and end it with

    ?>


    You server needs to support PHP and you have to save your pages with a .php file extension. You can use .php files as normal html documents with the exception of it being able to run php if your server can.

  • #6
    New Coder
    Join Date
    May 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes but then you have to save it .php and everything one my site is .html!!!!
    I've tried that and it doesn't work!

  • #7
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    does your server support php?

    I think you would have to get your host to allow running of PHP on .html files, although I think you can do it through .htaccess (?)

  • #8
    New Coder
    Join Date
    May 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, but I have a free host and you can't really tell them what to do when it'z free ! It doesn't allow .htaccess either!

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Well then you might be stuck, there is no secure way using javascript to block an ip address. Who is your host? And as they always say, you get what you pay for, in this case nothing. For the javascript method you would still need php. One other thing, php can't be parsed on an html file. It would have to be a .php in order to work.

  • #10
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Looks like you need a paid host...

  • #11
    New Coder
    Join Date
    May 2005
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, pay might be easy for you, but not for me!
    I have put a php counter on a HTML page and it worked, but it was made for a counter code only!

    See, you put the code at the top of the .html page and it works:

    Code:
    <!-- Counter/Statistics -->
    <script language="PHP" src=.php">
    </script>
    Now if only I could get it to work for every php code!

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by bratzmania
    Sorry, pay might be easy for you, but not for me!
    I have put a php counter on a HTML page and it worked, but it was made for a counter code only!

    See, you put the code at the top of the .html page and it works:

    Code:
    <!-- Counter/Statistics -->
    <script language="PHP" src=.php">
    </script>
    Now if only I could get it to work for every php code!
    That shouldn't work. Why it works I have no idea. Php goes into pages using <?php your script here?> I'm guessing its just a javascript called .php or something.

  • #13
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Exactly..that's weird why that would work. If you are able to run that kind of php in that way then your server must support php.....and if it supports PHP then your server must support *.php files unless that has been turned off somehow.

    And paid hosting comes very cheaply nowadays....you can get a basic server plan for about $20 a year or something from some cheap american hosts which run Linux servers.


  •  

    Posting Permissions

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