PHP Fatal error: Call to undefined function?

▼魔方 西西 提交于 2019-12-11 02:08:45

问题


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>';
    }

回答1:


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"); ?>


来源:https://stackoverflow.com/questions/47492353/php-fatal-error-call-to-undefined-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!