Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2002
    Location
    Ohio
    Posts
    3,139

    PHP writing to .htaccess question

    I'm wanting to write some code that automatically bans IP addresses if they try to do certain things on my site, but I have a little problem and I have no idea how to do it.

    Inside my .htaccess file, I have a line
    Code:
    ... Some htacess stuff...
    
    # Begin Auto-Ban IPs
    
    #End Auto-Ban IPs
    
    ... rest of my htaccess...
    How would I get PHP to add the "deny from x.x.x.x" between the above lines? I know how to write to files but this is new to me and I have not been able to successfully do this without it wiping out my .htaccess file.

    Does anyone know of any good tuts on how to do this?
    Glioblastoma Multiforme (GBM) Brain Cancer Awareness. May is Brain Cancer awareness month. Gray Matters!
    Incurable, 6-18 months prognosis, survivors longer than 3 years less than 1% chance.
    Don't like what I say? Ignore me.

  2. #2
    Join Date
    Sep 2002
    Location
    Illinois
    Posts
    2,304
    You could use Filesystem Functions

    http://www.php.net/manual/en/ref.filesystem.php

    (remeber to make file .htaccess writable for unix user nobody)

    There's also a great PHP class from PEAR project

    http://pear.php.net/package/File_HtAccess
    How's my programming? Call 1-800-DEV-NULL

  3. #3
    Join Date
    Jan 2002
    Location
    Ohio
    Posts
    3,139
    Thanks for the links...

    I ended up rearranging my htaccess and using error_log() to add entries.

    PHP Code:
            @error_log("deny from $ip[0].$ip[1].$ip[2]\r"3"./.htaccess"); 
    Glioblastoma Multiforme (GBM) Brain Cancer Awareness. May is Brain Cancer awareness month. Gray Matters!
    Incurable, 6-18 months prognosis, survivors longer than 3 years less than 1% chance.
    Don't like what I say? Ignore me.

Posting Permissions

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