Note that there are some explanatory texts on larger screens.

plurals
  1. POhtaccess creation through php
    primarykey
    data
    text
    <p>Before anything, I except the kind of answers "This is a BIGGGGG security issue", no problem with that however I would like a detailled answer of the risks please.</p> <p>Here is my problem: I am using php to automatically secure some folders, without having to edit the files inside. It then goes by .htaccess. The thing is that the .htaccess and .htpasswd files are created, with the good access rights (and so on for the folders) however it always returns a 500 internal error and when I check the error log there is nothing specifically written about the error. If I create the files manually, it works.</p> <p>Here is the php code:</p> <pre><code>$htpath = '../../.htpasswds/'.$ref; mkdir($htpath, 0750); $htpass = $htpath.'/.htpasswd'; $ourFileHandle = fopen($htpass, 'wb') or die("Can't create .htpasswd file."); $chars = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789"; $special_chars = '-_@#)([]|-='; $pass = $chars[rand(0,strlen($chars)-1)].$special_chars[rand(0,strlen($special_chars)-1)].$chars[rand(0,strlen($chars)-1)].rand(0, 9999).$chars[rand(0,strlen($chars)-1)].$special_chars[rand(0,strlen($special_chars)-1)]; $content = 'client_access'.$id.':'.crypt($pass, base64_encode($pass)); fwrite($ourFileHandle, $content) or die("Can't create .htaccess file."); fclose($ourFileHandle); $htpass = $path.'/.htaccess'; $handle = fopen($htpass, 'wb') or die("Can't create .htpasswd file."); $content = 'AuthType "Basic" '; $content .= "\n"; fwrite($handle, $content); $content = 'AuthUserFile "/home/thedigi1/.htpasswds/'.$ref.'/.htpasswd" '; $content .= "\n"; fwrite($handle, $content); $content = 'Require valid-user '; $content .= "\n"; fwrite($handle, $content); $content = 'RewriteOptions inherit'; $content .= "\n"; fwrite($handle, $content) or die("Can't create .htaccess file."); fclose($handle); </code></pre> <p>Do you have any idea of what may cause the problem? Or maybe a better solution please?</p> <p>Thanks a lot!</p> <p>Edit: here is the code of the htaccess created:</p> <pre><code>AuthType "Basic" AuthUserFile "/home/thedigi1/.htpasswds/A-161012-47/.htpasswd" Require valid-user RewriteOptions inherit </code></pre> <p>However I am already authentified through a htaccess to access to the php file which creates the htaccess, do you think it could be the problem?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload