【问题标题】:Store Location of .PEM where no one can access it but can be access in PHP.PEM 的存储位置,没有人可以访问它,但可以在 PHP 中访问
【发布时间】:2011-11-26 09:00:47
【问题描述】:

http://www.stellarwebsolutions.com/en/articles.php

我刚刚将 .pem 与 paypal 一起使用,但如果不将其放在我的 public_html/ 文件夹中,我找不到访问 .pem 的方法,我知道这可能不是最好的方法。有没有办法从 php 访问我的 ssh 的根目录?或我的 ssh 的其他区域?

【问题讨论】:

    标签: php ssh pem


    【解决方案1】:

    您可以轻松访问 public_html 文件夹之外的任何文件,您只需确保 Web 服务器用户可以访问该文件。例如:

    $ls -l
    total 8
    -rw-r--r-- 1 www-data www-data   12 Nov 26 13:08 test.txt
    drwxr-xr-x 2 www-data www-data 4096 Nov 26 13:11 www
    

    以下 php 脚本正在读取 test.txt:

    <?php
    
    $file = $_SERVER['DOCUMENT_ROOT'] . "/../test.txt"; // relative path
    //$file = "/opt/nguyen/test.txt"; //absolute path
    $contents = file($file);
    $string = implode($contents);
    
    echo $string;
    
    ?>
    

    您也可以将文件放在 public_html 文件夹中并使用 .htaccess 拒绝访问:

    <Files config.inc.php>
      order allow,deny
      deny from all
    </Files>
    

    【讨论】:

      猜你喜欢
      • 2021-11-10
      • 2021-05-01
      • 1970-01-01
      • 2019-01-14
      • 1970-01-01
      • 2010-10-24
      • 2014-09-05
      • 1970-01-01
      相关资源
      最近更新 更多