2

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>';
    }
Nick Leeman
  • 33
  • 1
  • 1
  • 4
  • I don't think include over http is possible here. But if you insist to do so, you probably need to check this thread https://stackoverflow.com/questions/13369529/full-url-not-working-with-php-include – Mochamad Gufron Efendi Nov 26 '17 at 02:07

2 Answers2

5

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 __DIR__.'/settings.php'; ?> 

If your settings.php file is located in some other folder 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);
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Amit Gupta
  • 2,771
  • 2
  • 17
  • 31
0

Also just an FYI for anyone trying to call a function within the same class in PHP, refer to the function like below:

return $this->doSomething($str);