代码之家  ›  专栏  ›  技术社区  ›  toddmo

当php文件位于doc root之外时如何使用图像生成php

php
  •  0
  • toddmo  · 技术社区  · 6 年前

    showcaptcha.php ,输出图像。

    <img src='/security/showcaptcha.php'>
    

    它工作得很好,所以里面的代码没有问题 是的。

    但现在,我该在我的img的src中放些什么呢?

    <img src='???showcaptcha.php'>
    

    <img src='<?php echo ??? ?>'>
    
    2 回复  |  直到 6 年前
        1
  •  2
  •   Dave    6 年前

    将真正的代码放在php include路径(位于文档根目录之外)中的一个目录中,并在security目录中保留一个存根,其作用仅限于 require('showcaptcha.php'); 是的。有人四处挖掘只会知道文件存在于某个地方,但如果他们在文档根目录中,他们将无法看到或找到它。

        2
  •  1
  •   tadeubarbosa    6 年前

    public 存放公共文件的文件夹(或其他名称),对吗?像这样的:

    - src/
    - public/
      - index.php
    - .htaccess
    

    在这种情况下,您不能使用 ../showcaptcha.php .htaccess .htaccess接口 正在将用户发送到 公众的 url 类似于:

    ...
    # access the `images/captcha.jpg` to get the result
    RewriteRule ^images/captcha.jpg$ ./path/to/showcaptcha.php
    
    # send all urls that not is a folder or a directory to public/index.php, then init the magic with friendly url in this file
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule .$ public/index.php