markmax33 Posted September 19, 2008 Share Posted September 19, 2008 Team, I am trying to create an external file for my common functions to be called by other files. My functions.php file looks like this: <? function some_function{ blah; blah; } ?> My main file looks like this: <? include('../functions.php'); // seems to be working correctly to this point some_function(); //when I call this function the PHP hangs and I don't even get an error, just a white screen of death! ?> It appears like the include portion is work correctly, but the some_function(); is not working. I have a ton variables that are ???defined in the main file that need to be used by some_function. I read all of the websites on this topic and I can't figure it out. Does someone have a good example I can follow? Is there a rule about parsing or something? Do I need to change functions.php to functions.inc? Wouldn't that be a security concern because someone could access functions.inc and download it? I have passwords and stuff that I need to keep secure in functions.php! Incidentally I checked and the function runs in the main file correctly with all of it's contents. I just can't remove it and put it in the external functions.php and call it properly! Doh! Thanks for any of your expert advice in advance! -Max Quote Link to comment https://forums.phpfreaks.com/topic/124982-solved-functions-in-include-files/ Share on other sites More sharing options...
Maq Posted September 19, 2008 Share Posted September 19, 2008 Post the code for some_function(); Are you sure you have the correct dir path for the include? Quote Link to comment https://forums.phpfreaks.com/topic/124982-solved-functions-in-include-files/#findComment-645800 Share on other sites More sharing options...
PFMaBiSmAd Posted September 19, 2008 Share Posted September 19, 2008 Add the following two lines immediately after your first <?php tag in your main code - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/124982-solved-functions-in-include-files/#findComment-645805 Share on other sites More sharing options...
Maq Posted September 19, 2008 Share Posted September 19, 2008 The most suggested line of PHP code that helps pinpoint why code is not working - error_reporting(E_ALL); Hehe, error_reporting(E_ALL); is your best friend... Quote Link to comment https://forums.phpfreaks.com/topic/124982-solved-functions-in-include-files/#findComment-645812 Share on other sites More sharing options...
markmax33 Posted September 19, 2008 Author Share Posted September 19, 2008 It does appear as if it isn't calling the file correctly. The functions.php is in the root with the main page. Warning: include(../functions.php) [function.include]: failed to open stream: No such file or directory in /home/u3/markmax33/html/Beta/testme.php on line 7 Warning: include() [function.include]: Failed opening '../functions.php' for inclusion (include_path='.:/usr/local/share/pear') in /home/u3/markmax33/html/Beta/testme.php on line 7 Fatal error: Call to undefined function get_user_id() in /home/u3/markmax33/html/Beta/testme.php on line 38 Quote Link to comment https://forums.phpfreaks.com/topic/124982-solved-functions-in-include-files/#findComment-645815 Share on other sites More sharing options...
markmax33 Posted September 19, 2008 Author Share Posted September 19, 2008 Looks like I fixed it. Dumb error: include('functions.php'); NOT include('../functions.php'); Thanks for the tip on the error reporting! You da man! Quote Link to comment https://forums.phpfreaks.com/topic/124982-solved-functions-in-include-files/#findComment-645824 Share on other sites More sharing options...
Maq Posted September 19, 2008 Share Posted September 19, 2008 You're calling the include(../functions.php) from "/home/u3/markmax33/html/Beta/testme.php"? Then make sure that functions.php is in the Beta folder. Quote Link to comment https://forums.phpfreaks.com/topic/124982-solved-functions-in-include-files/#findComment-645825 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.