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.

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

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化