PHP 致命错误:调用未定义的函数? [英] PHP Fatal error: Call to undefined function?

查看:56
本文介绍了PHP 致命错误:调用未定义的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以当我在我的虚拟主机上托管我的网站时,我的网站出现了问题.我收到此错误:

PHP 致命错误:调用未定义的函数 getSkillIcons()

奇怪的是,在本地(Xampp)它工作得很好.

这就是我如何包含函数(在 index.php 中):

这就是我所说的(index.php):

<?php getSkillIcons(explode(',', Skills));?>

这是我定义技能的方式(settings.php)

define("skills", "Test1,Test2,Test3,Test4");

这是函数本身:(settings.php)

function getSkillIcons($skills) {echo '<a href="?skill=Overall" title="Overall" data-toggle="tooltip" data-placement="top"><img src="http://sub.website.com/incl/img/skill_icons/Overall-icon.png" class="skill-icon"></a>';for ($i = 0; $i < count($skills); $i++) {$tooltip = 'title="'.$skills[$i].'" data-toggle="tooltip" data-placement="top"';echo '<a href="?skill='.$skills[$i].'" '.$tooltip.'><img src="http://sub.website.com/incl/img/Skill_icons/'.$skills[$i].'-icon.png" class="skill-icon"></a>';}

解决方案

Call to undefined function error 清楚地表明它没有在你定义的地方得到你的函数.原因是您使用 http 附加了 settings.php 文件的完整路径.

您需要在 'index.php' 的顶部包含 settings.php 文件而不带 http 路径,并确保 settings.php文件仅位于您的项目中.如果它与 index.php 位于同一文件夹中,则只需像下面这样包含即可.

<?php 包含 'settings.php';?>

如果您的 settings.php 文件位于其他网站但位于同一服务器中,那么您可以使用 $_SERVER['DOCUMENT_ROOT'] 包含该文件,如下所示:

如果您的 settings.php 文件位于其他网站和其他服务器上,那么您需要更新 php.ini<中的 allow_url_include=On/code> 这是主要安全风险.所以,如果您信任该网站,那就只做它.

//极度不安全:<?php include("http://sub.website.com/incl/Settings.php");?>

So i have a problem with my website when im hosting it on my webhost. i get this error:

PHP Fatal error:  Call to undefined function getSkillIcons()

The weird thing is that locally(Xampp) it works just fine.

This is how i included the function(in index.php):

<?php include 'http://sub.website.com/incl/Settings.php'; ?>

this is where i call it (index.php):

<div class="panel-body" style="text-align:center">
<?php getSkillIcons(explode(',', skills)); ?>
</div>

This how i defined skills (settings.php)

define("skills", "Test1,Test2,Test3,Test4");

this is the function itself: (settings.php)

function getSkillIcons($skills) {
    echo '<a href="?skill=Overall" title="Overall" data-toggle="tooltip"            data-placement="top"><img src="http://sub.website.com/incl/img/skill_icons/Overall-icon.png" class="skill-icon"></a>';
    for ($i = 0; $i < count($skills); $i++) {
        $tooltip = 'title="'.$skills[$i].'" data-toggle="tooltip" data-placement="top"';
        echo '<a href="?skill='.$skills[$i].'" '.$tooltip.'><img src="http://sub.website.com/incl/img/skill_icons/'.$skills[$i].'-icon.png" class="skill-icon"></a>';
    }

解决方案

Call to undefined function error clearly shows that its not getting your function where you have defined. Reason is you are attaching full path of settings.php file with http.

You need to include settings.php file without http path at the top of 'index.php' and make sure settings.php file is located in your project only. If it is located at the same folder with index.php, then simply include like below.

<?php include 'settings.php'; ?> 

If your settings.php file is located in some other website but in your same server then you can use $_SERVER['DOCUMENT_ROOT'] to include that file like below:

<?php 
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/yourpath/settings.php";
include_once($path);
?>

If your settings.php file is located in some other website and some other server then you need to update allow_url_include=On in your php.ini that is the MAJOR SECURITY RISK. So, if you trust the website then only do it.

// Extremely insecure:
<?php include("http://sub.website.com/incl/Settings.php"); ?>

这篇关于PHP 致命错误:调用未定义的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆