Skip to main content

php script to write to .htaccess file as root or user

Comments

3 comments

  • cPanelMichael
    New hello everyone! I'm trying to write to a .htaccess of my clients with a php script, so i tried fopen and fwrite but its failing to open the .htaccess on another server/domain but it's only working on the server that contains the script. Is there any way i can achieve this as a root administrator using the user`s username ?

    Hello, Do you notice a specific error message in the error_log file within the script's document root, or in /usr/local/apache/logs/error_log? Thank you.
    0
  • mugo
    Hello, Do you notice a specific error message in the error_log file within the script's document root, or in /usr/local/apache/logs/error_log? Thank you.

    Hey Michael. its giving me this error message
    "Warning: fopen(http://domain.com/.htaccess): failed to open stream: HTTP wrapper does not support writeable connections in....." Im using this code below: as $value) { $valu = implode($value); if (!empty($valu)) { $link[] = $valu; $folder[] = key($value); } } $length = count($link); $fp = fopen ("http://domain.com/.htaccess", "r"); for($i =0; $i < $length ; $i++) { if (mkdir($folder[$i], 0755, true)) { if (!$fp) { echo "

    Unable to write remote file.\n"; exit; } else{ fwrite($fp, ''.PHP_EOL.'RedirectMatch 301 /'.$folder[$i].'/(.*) https://'.$link[$i].'/$1'); echo "file written"; } } } fclose($fp); ?>


    0
  • cPanelMichael
    Hello, PHP documents this topic at: PHP: Using remote files - Manual Let us know if this helps. Thank you.
    0

Please sign in to leave a comment.