【问题标题】:require_once() function unable to include functions()require_once() 函数无法包含函数()
【发布时间】:2012-03-22 12:37:38
【问题描述】:

index.php

<?php
require_once('fr.php');
header('Location:'.abspath().directory());
?>

fr.php

<?php
require_once('functions.php');
?>

functions.php

function abspath()
{
return $_SERVER['DOCUMENT_ROOT'];
}

现在当我转到 index.php 时,它给了我这个错误:-

Fatal error: Call to undefined function abspath() in C:\xampp\htdocs\index.php on line 3

【问题讨论】:

  • 这看起来不错。您是否 1000% 确定所有文件都是正确且最新的?
  • 您的要求与文档相关。 functions.php 是否与 index.php 和 fr.php 在同一位置?
  • 这个函数不在你试图包含的这个 .php 文件中。或者您的包含订单不正确。首先你必须包含它,然后你才能使用它。
  • 为 index.php 和 fr.php 发布的脚本包含 &lt;?php 标记,functions.php 的脚本没有。您是在这里忘记了它还是在您的服务器上的文件中也丢失了它?
  • 我知道这不是问题.. 但是您正在重定向到路径而不是 url

标签: php function include absolute-path document-root


【解决方案1】:

嘿,我所有评论的人都是对的……我不知道为什么会这样,但是当我重新启动我的 xampp 时,它对我来说很好:)

所以这是 100% 正确的

index.php

<?php
require_once('fr.php');
header('Location:'.abspath().directory());
?>

fr.php

<?php
require_once('functions.php');
?>

functions.php

function abspath()
{
return $_SERVER['DOCUMENT_ROOT'];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-06
    • 2023-03-31
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多