dfowler Posted August 17, 2010 Share Posted August 17, 2010 Hey guys, I wrote a function called isServer() so I can quickly move files from my local machine to my server without modifying too much. The function is as follows: function isServer() { if ($_SERVER['SERVER_NAME'] == 'myservername') { return(true); } else { return(false); } } // isServer() I have placed this function in a system.php file I created that is used to simply to keep things in order. That files contents are: <?php session_start(); function isServer() { if ($_SERVER['SERVER_NAME'] == 'myservername') { return(true); } else { return(false); } } // isServer() include "configuration.php"; include "functions.php"; include "functions_sql.php"; include "functions_soap.php"; include "functions_mail.php"; if (isProductionServer()) { $dbhost = 'db'; $dbuser = 'db_user'; $dbpass = 'pass123'; } else { $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'pass'; } $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'my_database'; mysql_select_db($dbname) or die ('Selected database does not exist'); ?> The problem I am having is for some reason none of the include files are recognizing the function. For example, the functions_mail.php file references the function to determine which emails to send (because the different environments have different modules and such installed). I know this is something easy, but I can't seem to figure it out. Thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/210973-include-issues/ Share on other sites More sharing options...
JonnoTheDev Posted August 17, 2010 Share Posted August 17, 2010 The problem I am having is for some reason none of the include files are recognizing the function. What do you mean by recognising? Are you getting an undefined function error? Have you done a simple echo test i.e <?php if(!isServer()) { print "not my server"; exit(); } ?> On another note, remove the braces from return values! <?php function isServer() { if ($_SERVER['SERVER_NAME'] == 'myservername') { return true; } return false; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/210973-include-issues/#findComment-1100386 Share on other sites More sharing options...
dfowler Posted August 17, 2010 Author Share Posted August 17, 2010 The problem I am having is for some reason none of the include files are recognizing the function. What do you mean by recognising? Are you getting an undefined function error? Have you done a simple echo test i.e <?php if(!isServer()) { print "not my server"; exit(); } ?> On another note, remove the braces from return values! <?php function isServer() { if ($_SERVER['SERVER_NAME'] == 'myservername') { return true; } return false; } ?> Thanks for the recommendation. Yes, I have done a simple test and get the following: Fatal error: Call to undefined function isServer() in C:\server\wwwroot\includes\functions_mail.php on line 5 Quote Link to comment https://forums.phpfreaks.com/topic/210973-include-issues/#findComment-1100412 Share on other sites More sharing options...
dfowler Posted August 17, 2010 Author Share Posted August 17, 2010 Just to clarify, I know that by going directly to that file it won't know the function. However, I have a separate page that utilizes a function on that page that won't load unless I comment out the reference. More details: step6.php includes system.php that I referenced on first post. step6.php calls sendServerEmail() which is defined in functions_mail.php sendServerEmail() is within an if statment if(isServer()) step6.php loaded a blank screen until I commented out the if in functions_mail.php Quote Link to comment https://forums.phpfreaks.com/topic/210973-include-issues/#findComment-1100417 Share on other sites More sharing options...
DavidAM Posted August 17, 2010 Share Posted August 17, 2010 I notice in your OP you defined the function as isServer(), but then a few lines lower you called it as isProductionServer(). Are you doing this in your code, or was that a typo in the post? Quote Link to comment https://forums.phpfreaks.com/topic/210973-include-issues/#findComment-1100451 Share on other sites More sharing options...
PFMaBiSmAd Posted August 17, 2010 Share Posted August 17, 2010 I'm going to guess that your include statement is failing and in php's brilliant wisdom of hiding various types of error messages, your error_reporting/display_errors settings are not set up to show you all the errors that are occurring. I recommend setting error_reporting to E_ALL and display_errors to ON in your master php.ini on your development system so that all the php detected errors will be reported and displayed. Quote Link to comment https://forums.phpfreaks.com/topic/210973-include-issues/#findComment-1100455 Share on other sites More sharing options...
dfowler Posted August 17, 2010 Author Share Posted August 17, 2010 I notice in your OP you defined the function as isServer(), but then a few lines lower you called it as isProductionServer(). Are you doing this in your code, or was that a typo in the post? Typo in my post. Quote Link to comment https://forums.phpfreaks.com/topic/210973-include-issues/#findComment-1100459 Share on other sites More sharing options...
dfowler Posted August 17, 2010 Author Share Posted August 17, 2010 I'm going to guess that your include statement is failing and in php's brilliant wisdom of hiding various types of error messages, your error_reporting/display_errors settings are not set up to show you all the errors that are occurring. I recommend setting error_reporting to E_ALL and display_errors to ON in your master php.ini on your development system so that all the php detected errors will be reported and displayed. Good guess! I was putting ini_set('error_reporting', E_ALL); at the top of the pages. However, once I manually modified my dev system it showed an error I wasn't seeing before. Looks like everything is working now. Thanks for the help, sometimes it good to get a fresh approach! Quote Link to comment https://forums.phpfreaks.com/topic/210973-include-issues/#findComment-1100462 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.