2016-12-12 12 views
0

phpで私は電子メールを "email.txt"に送信する連絡フォームを作成しました。唯一の問題は、誰でも "example.com/email.txt"というURLの文書を見ることができることです。LAMPサーバーのファイルを保護する方法は?

このような私のPHPコードを見て:

<!DOCTYPE html> 
<html> 
    <head></head> 
    <body> 
     <?PHP 
     $email = $_POST["emailaddress"]; 

     $to = "[email protected]"; 
     $subject = "New Email Address for Mailing List"; 
     $headers = "From: $email\n"; 

     $message = "A visitor to your site has sent the following email address to be added to your mailing list.\n 

     Email Address: $email"; 

     $user = "$email"; 
     $usersubject = "Thank You"; 
     $userheaders = "From: [email protected]\n"; 

     $usermessage = "Thank you for subscribing to our mailing list."; 

     mail($to,$subject,$message,$headers); 

     mail($user,$usersubject,$usermessage,$userheaders); 

     $fh = fopen("email.txt", "a"); 
     fwrite($fh, $email); 
     fclose($fh); 

     ?> 

     <html> 
      <body> 
       <table width="400" border="0" cellspacing="0" cellpadding="0"> 
        <tr> 
         <td> 
          <div align="center">Thank You, Your Information Has Been Submitted</div> 
         </td> 
        </tr> 
       </table> 
      </body> 
     </html> 
    </body> 
</html> 

誰でも今私は、ドキュメントを保護することができますどのように?

答えて

2

ファイルがディレクトリの外部にあるように移動します。 HTTPサーバーのルートディレクトリ。

私のサーバーのディレクトリ構造のようなものになります。

/hosts/example.com/apache # For server configuration files 
/hosts/example.com/pages # For normal files to be served 
/hosts/example.com/data # For data files (like the one you are talking about) 
/hosts/example.com/logs # For log files 
/hosts/example.com/stats # For reports generated from log files 

代わりに(ただし、追加の複雑さを持つ)を、代わりにRDBMSを使用しています。


(ただし、構成が壊れた場合にセキュリティ上の問題が発生する可能性が高くなります)、そのファイルへのアクセスを特に拒否するようにサーバーを構成します。例えばApacheには<Files>ブロックとAllow/Denyディレクティブがあります。

関連する問題