visualazza Posted August 14, 2010 Share Posted August 14, 2010 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? Quote Link to comment Share on other sites More sharing options...
Alex Posted August 14, 2010 Share Posted August 14, 2010 We need to see relevant code. Quote Link to comment Share on other sites More sharing options...
visualazza Posted August 14, 2010 Author Share Posted August 14, 2010 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>"); } } Quote Link to comment Share on other sites More sharing options...
Alex Posted August 14, 2010 Share Posted August 14, 2010 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. Quote Link to comment Share on other sites More sharing options...
visualazza Posted August 14, 2010 Author Share Posted August 14, 2010 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 ?> Quote Link to comment Share on other sites More sharing options...
visualazza Posted August 14, 2010 Author Share Posted August 14, 2010 ok so after doing a few (many many) checks i have found that it is the fact i am using $_SERVER['HTTP_HOST'] in the require (sorry i forgot to put that in the first post) Why is it stopping is from working? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 14, 2010 Share Posted August 14, 2010 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. Quote Link to comment Share on other sites More sharing options...
visualazza Posted August 14, 2010 Author Share Posted August 14, 2010 but thats the thing, i take it out and it all works as it should so Quote Link to comment Share on other sites More sharing options...
visualazza Posted August 14, 2010 Author Share Posted August 14, 2010 ive made a separate couple of pages and the same thing occurs temp.php <?php require("http://".$_SERVER['HTTP_HOST']."/testfunc.php"); test(); ?> testfunc.php <?php function test() { echo("The function works"); } ?> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 14, 2010 Share Posted August 14, 2010 You cannot include a file using a URL. You need to use a local file path! Eg require $_SERVER['DOCUMENT_ROOT'] . '/testfunc.php'; Quote Link to comment Share on other sites More sharing options...
visualazza Posted August 14, 2010 Author Share Posted August 14, 2010 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 14, 2010 Share Posted August 14, 2010 Ok, omit that variable and do require 'testfunc.php'; Quote Link to comment Share on other sites More sharing options...
visualazza Posted August 14, 2010 Author Share Posted August 14, 2010 again its a problem as i need to be able to access the file from another folder lower down Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 14, 2010 Share Posted August 14, 2010 Can you post your sites file structure.. You can go higher up in your directory structure using ../ Quote Link to comment Share on other sites More sharing options...
visualazza Posted August 14, 2010 Author Share Posted August 14, 2010 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) Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 14, 2010 Share Posted August 14, 2010 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. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 14, 2010 Share Posted August 14, 2010 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'; Quote Link to comment Share on other sites More sharing options...
visualazza Posted August 14, 2010 Author Share Posted August 14, 2010 problem with that is that in area1, functions.php wont be found because the included header has functions/functions.php not ../../functions/functions.php Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 14, 2010 Share Posted August 14, 2010 I just tested it and it worked. I went to site.com/areas/area1/ I asummed thats how you called index.php in areas/area1 Quote Link to comment Share on other sites More sharing options...
visualazza Posted August 14, 2010 Author Share Posted August 14, 2010 but i dont want to duplicate header.php or functions.php header.php is in the root folder functions.php is in functions folder 1 below root Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 14, 2010 Share Posted August 14, 2010 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] Quote Link to comment Share on other sites More sharing options...
visualazza Posted August 15, 2010 Author Share Posted August 15, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.