Jump to content

Recommended Posts

hi,

 

im getting the error

 

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

 

after including the functions.php file i wrote. It does include it but the data isnt being recognised from it. If i copy/paste the notification() function into index.php it works.

 

Can someone tell me why so i can fix it?

Link to comment
https://forums.phpfreaks.com/topic/210742-functions-dont-exist-but-they-do/
Share on other sites

index.php

require("functions/functions.php");

 

functions.php

function notification()
{
$error = $_GET['error'];

if ($error != "")
{
switch($error)
{
case 0:
        $error =  "Unspecified Error";
        break;
    case 1:
        $error =  "i equals 1";
        break;
    case 2:
        $error =  "i equals 1";
        break;
}
echo("<div class='error'>$error</div>");
}
}

That doesn't really help. Can you post your entire index page up to the point where you're calling the function? There could also be a problem somewhere else in your functions.php file so post the full source to that please.

sorry but i cant post the index.php file due to the project being completly secret but other than requiring functions.php and calling notification() its all just design html.

 

The functions.php file is (at the moment) just what i posted before but in <?php ?>

i forgot to put that in the first post

 

If you are not posting (simple as copy/pasting) the actual code that exhibits the symptom, no one can help you with your actual problem.

 

$_SERVER['HTTP_HOST'] has absolutely nothing to do with forming a file system path to where your file might be located on the server.

using document_root is a problem

 

my localhost is fine with it but my server is weird and throughs errors saying it cannot find the file

 

You do realize that if you had continued with this problem in your first thread about it, you could probably have solved it by now.

 

Your $_SERVER['DOCUMENT_ROOT'] is apparently empty. Your web host can probably fix it by correcting the vhosts definition.

 

However, after your php script starts, $_SERVER['DOCUMENT_ROOT'] is just a variable that you could set yourself with the correct value for your actual document root and it would allow you to form absolute file system paths to where your include/require files are actually located.

To call header.php in areas/area1/index.php you'd use the following path

require '../../header.php';

 

In header.php you'd use the following path to call functions.php

require 'functions/functions.php';

 

To call header.php in the root index.php file you'd use the following file path.

require 'header.php';

I haven't duplicated those files.

 

I setup the file structure as you posted earlier

root

  functions

    functions.php

  areas

    area1

      index.php (this calls header.php 2 levels higher)

  header.php (this calls function.php)

  index.php (this calls header.php from same folder)

 

Download the attached zip. Extract to your root folder. Go site.com/visuallaza to test

 

[attachment deleted by admin]

thanks for your help, it works now.

 

I thought php got the contents of the required file like html does with css and other documents where is gets the contents and acts like that file is in the same folder as the one that is calling it.

 

Guess not

 

Thanks again for all your help

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.