doumo1807831 2016-06-07 06:23
浏览 43
已采纳

在inetpub中存储敏感的ini文件(对于PHPMailer凭据)但在IIS中的wwwroot之外 - 是“公共”吗?

I am using PHPMailer to send emails in PHP using SMTP with username & password authorization.

It works well, but I am concerned about hard coding the SMTP username & password in the php file.

Other threads on Stack Overflow have suggested "storing the username & password in an 'ini' file outside of the web server / document root"

So I've stored it in inetpub, but before wwwwroot. Eg. E:\inetpub\smtp.ini

Where as my websites are stored in E:\inetpub\wwwroot\exampleWebsite

My question is: Is my smtp.ini file stored in a 'non-public' area? In other words, if a website user can access wwwroot, can they also access a file in inetpub? Or is there a better folder / sub folder I should be storing it in?

My PHP code is as follows:

$path = realpath('/inetpub/smtp.ini');
$config = parse_ini_file($path, true);
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'outlook.office365.com';
$mail->SMTPAuth = true; 
$mail->Username = $config['smtp']['un'];
$mail->Password = $config['smtp']['pw'];
// ... rest of mail function ...
$mail->send();
  • 写回答

1条回答 默认 最新

  • dousou3027 2016-06-07 06:49
    关注

    What you're doing is safe: the file is outside the web root and so has no external URL (assuming your server doesn't allow silly things like letting relative URLs go out of the web root like ../../smtp.ini). You could protect it further by making it render to nothing, for example by adding a line like this at the start and then saving it as a .php file:

    ;<?php return false;
    

    This looks like a harmless comment to an ini-file parser, but will produce a blank page if accessed as a PHP file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度