Forum Moderators: coopster

Message Too Old, No Replies

I'm getting an 'error: Call to undefined function'

but I swear it's there

         

Trisha

5:35 am on Mar 2, 2004 (gmt 0)

10+ Year Member



I feel really embarrassed (sp?) asking this here but I keep looking and looking at this and can't figure out what is wrong. I don't do very much php stuff, so maybe I'm missing some simple, obvious thing.

I have a file called 'myfile.php' that has an include statement to include the file 'functions.php'. 'functions.php' contains a function called 'dbconnect', which connects to a database.

I keep getting:

'error: Call to undefined function: dbconnect() in ...myfile.php'

I know the file functions.php is being found though because I put the word 'test' at the beginning of it, and it shows up when viewing .myfile.php'. If I copy and paste the function 'dbconnect' into 'myfile.php' everything works fine, so there is nothing wrong with the function itself. It just can't be found when it is in the included file, 'functions.php'.

I keep thinking I'm missing something obvious here. It's been a long time since I've done any php/mysql coding, so maybe I've forgotten something really basic. (I did remember to upload in ASCII though.) Could it be some permissions problem with the file 'functions.php'? Anyone have any guesses at what might be causing this?

coopster

1:10 pm on Mar 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The only thing I can think of is perhaps you need to include your functions.php before you execute the dbconnect() function?
include("functions.php"); // <-- include before calling! 
dbconnnect();

Trisha

5:43 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



I got the problem figured out and it's working now! I had the path to the functions.php file as an absolute path like:

include ("http://www.mydomain/functions.php")

I changed it to a relative path like this:

include ("../../../functions.php")

and now it works! I had no idea it needed to be done that way. I decided to try it only because that was how I did it for another site a couple of years ago.

Thanks for the suggestion though coopster, I did call the includes file before I tried to execute the dbconnect() function though.

I do have a follow up security question though, if anyone is reading this. I've forgotten, but are there security issues with the functions.php file containing the db password, etc.? Should the permissions for that file be set to 755 or something? Or is best to place that file outside of the directory where the regular html files are?

coopster

6:07 pm on Mar 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Best to keep them outside of the public root. A quick search on this site for PHP include path and security will turn up plenty of discussion. A couple to get you started...
Performance and Multiple Include User Functions [webmasterworld.com]
Accessing PHP includes folder in root dir from 2+ levels deep [webmasterworld.com]

Trisha

7:04 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



Thank you coopster! I thought it was best to do it that way - I will read those threads!

Bigjohn

12:44 pm on Mar 3, 2004 (gmt 0)

10+ Year Member



Perhaps its a lack of coffee talking, but could one not also put the .PHP files that you want to hide into a MYSQL database as blobs?