【问题标题】:How do I allow PHP to run when the script is not in the URL?当脚本不在 URL 中时,如何允许 PHP 运行?
【发布时间】:2017-03-26 13:46:13
【问题描述】:

当我转到我网站中的某个文件夹时,我想运行一个 PHP 脚本,但它没有显示在 URL 中。

我希望 /number/number.php 在用户访问 /number/ 时运行

我是否需要使用 .htaccess 文件来执行此操作?

【问题讨论】:

标签: php .htaccess url web


【解决方案1】:

您可以尝试在此文件夹上创建一个 index.php 文件,并使用包含语句来包含 number.php。就我现在而言,每次在 URL 处键入文件夹时,服务器都会搜索要运行的索引文件,并且 index.php 不包含在 url 中。

【讨论】:

    【解决方案2】:

    如果您希望脚本在不让用户访问该页面的情况下运行.. 您可以简单地将文件包含在另一个文件中.. 例如,您可以在文件夹 /number/ 中创建一个 index.php,其中包含以下代码:

    <?php
    include("./numbers.php"); /* the './' means, it refers to the same folder */
    ?>
    

    【讨论】:

      猜你喜欢
      • 2015-09-20
      • 2016-07-18
      • 1970-01-01
      • 2016-04-09
      • 1970-01-01
      • 1970-01-01
      • 2020-09-12
      • 2021-02-02
      • 2020-06-19
      相关资源
      最近更新 更多