Jump to content

Include issues


dfowler

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/210973-include-issues/
Share on other sites

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;
} 
?>

 

Link to comment
https://forums.phpfreaks.com/topic/210973-include-issues/#findComment-1100386
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/210973-include-issues/#findComment-1100412
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/210973-include-issues/#findComment-1100417
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/210973-include-issues/#findComment-1100455
Share on other sites

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!
Link to comment
https://forums.phpfreaks.com/topic/210973-include-issues/#findComment-1100462
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.