WordPress.org

Support

Support » Plugins and Hacks » BulletProof Security » [Resolved] Before I install…

[Resolved] Before I install…

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author AITpro

    @aitpro

    Yep, just do not lock your root .htaccess file or check if the script automatically unlocks the root .htaccess file, writes to it and locks it again. This is a very simple thing to do so if this script is not doing this then the code would be something like this.

    $filename = ABSPATH . '.htaccess';
    $stringReplace = @file_get_contents($filename);
    
    if ( file_exists($filename) ) {
        // unlock the file first
        chmod($filename, 0644);
        // whatever code needs to be written here
       if ( file_put_contents($filename, $stringReplace) ) {
       // lock the file after writing to it
       chmod($filename, 0404);
       }
    }

    Thanks. Due to a brain injury I forgot all coding knowledge so the above is a foreign language.

    I’m going to ask my script coder if he can come here and decipher 🙂

    Plugin Author AITpro

    @aitpro

    For the whatever code needs to be written section of the function above this is the simplest way to do a match and replacement. For “replace the landmark code with some new code” you would add the landmark code back into the root .htaccess file plus your new code so that the original root .htaccess file code is replaced and you additionally add your new code too.

    // whatever code needs to be written here
    $pattern = '/a landmark pattern match in the root htaccess file/';
    
    if ( preg_match($pattern, $stringReplace, $matches) ) {
       $stringReplace = preg_replace('/the landmark pattern match code/', "replace the landmark code with some new code", $stringReplace);
    }
    Plugin Author AITpro

    @aitpro

    Putting the whole thing together it would look like this.

    $filename = ABSPATH . '.htaccess';
    $stringReplace = @file_get_contents($filename);
    $pattern = '/a landmark pattern match in the root htaccess file/';
    
    if ( file_exists($filename) ) {
        // unlock the file first
        chmod($filename, 0644);
    
       // whatever code needs to be written here
       if ( preg_match($pattern, $stringReplace, $matches) ) {
          $stringReplace = preg_replace('/the landmark pattern match code/', "replace the landmark code with some new code", $stringReplace);
       }
    
       if ( file_put_contents($filename, $stringReplace) ) {
          // lock the file after writing to it
          chmod($filename, 0404);
       }
    }

    Thank you! The script I had conflicts so it was removed. I’m looking at Ban Hammer (here) but … that issue will rise again and I can’t alter that script.

    Plugin Author AITpro

    @aitpro

    Then just do not lock your root .htaccess file if you need to allow another plugin to dynamically write to the root .htaccess file at any time. Also set AutoLock to Off on the BPS Edit/Upload/Download page.

    Ok, let’s see if I have this right. I’ll use Ban Hammer and your script. Through your script, I will set it to NOT lock .htacces plus I will set AutoLock to off on Edit/Upload/Download page.

    Since I have no memory, if I’m right, I’ll print that out before I totally f^*& up my sites.

    (This is MUCH easier. I canceled the custom script, no additional coding, plus the two scripts I will use have support here)

    Plugin Author AITpro

    @aitpro

    Yep, that is correct. On the Edit/Upload/Download page click these 2 buttons: Unlock htaccess File and Turn Off AutoLock.

    Printing, downloading and thanking you sincerely for your help. Saved me $$$ and aggravation and time.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] Before I install…’ is closed to new replies.
Skip to toolbar