dpqmu84646 2014-04-13 15:06
浏览 247
已采纳

PHP使用包含文件中的函数

I uploaded my website on a webserver and now it displays following error:

Fatal error: Call to undefined function getactualeventid()

This function is defined in my file functions.php and i include it on the top of my index.php file by following line:

include '.\functions.php';

The file functions.php is in the same directory as my index.php. Are there settings on the server that I need to change?

//EDIT

In the beginning I used include 'functions.php'; but only a blank page has been loaded, so I tried it with include '.\functions.php'; and then I got at least a clear error message.

I also tried include_once but it doesn't work. I tested the whole stuff on my localhost by using XAMPP where it runs without any problems.

I still don't know what the problem is.

  • 写回答

5条回答 默认 最新

  • duanlieshuang5330 2014-04-13 15:19
    关注

    First, the syntax should be:

    include('functions.php');
    

    But I would recommend using include_once instead of include to avoid scenarios where your script might inadvertently attempt to load the same file more than once.

    include_once('functions.php');
    

    But I would also encourage you to use a base path of some sort to prefix the location of the file so you are not constantly juggling relative locations.

    For example, in your main config file, you can define a base path like this:

    $BASE_PATH = '/the/path/to/the/codebase/';
    

    Then when you do an include_once, the syntax would be:

    include_once($BASE_PATH . 'functions.php');
    

    The benefit of this is no matter how deeply nested your codebase becomes, you will always be anchored to the value of $BASE_PATH. And your life will be made tons easier thanks to not having to worry about relative path issues.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿