Jump to content

Included file not found--SOMETIMES?


doni49

Recommended Posts

I have a bit of a problem.  My php file has several include calls--most of the included files are in the same folder.  But SOMETIMES one file is not able to be located even though the other included files CAN be located.  The one file that is throwing not found errors is [b]FRDBConnect.inc[/b].  The include file (comm_config.inc) uses the "set_include_path" function to change the include path to include the folder containing my include files.

The times that I've loaded the page myself--no errors.  When the techs at the web host, load the page--no errors.  But Thursday night around 9pm, I recieved an error message (from the error handler) informing me that someone tried loading the page and [b]FRDBConnect.inc[/b] could not be found.  This was the third message over the course of the previous 4 days or so.

My web host INSISTS that it's not a server issue and MUST be a coding issue.  But that just doesn't make any sense to me.  If it's a coding issue, wouldn't it either work ALWAYS or NEVER work?

[code]
<?php
//This is index.php
$pgTitle = "Welcome to mysite1.com";
include("header.inc");
require_once ('FRDBConnect.inc'); // Connect to the database.
?>

Page specific HTML content here.

<?php
include("footer.inc");
?>
[/code]

[code]
<?php
//This is header.inc (in the same folder as index.php).
include("/home2/username/includes/common/comm_config.inc");//  <==This include file sets up configuration for all three of my web sites.  Code shown below.
include("/home2/username/includes/Site1/header2.inc");
?>
[/code]

[code]
//This is comm_config.inc
<?php
$incpath = get_include_path();
$incpath = explode(":", $incpath);

if (empty ($_SESSION['sessionStarted'])){
$_SESSION['sessionStarted'] = TRUE;
ob_start();
session_start();
}


$servername = explode(".",$_SERVER['SERVER_NAME']); 
switch ($servername[1]) {
case 'site1':
  $incpath2 = "/home2/username/includes/site1";
  break;
case 'site2':
  $incpath2 = "/home2/username/includes/site2";
  break;
case 'site3':
  $incpath2 = "/home2/username/includes/site3";
  break;
}
//pull the include_path apart so that I can rebuild it
//as ".:my_common_include_folder:my_site_specific_include_folder:default_include_folders_as_specified_by_web_host"
$incpath3 = "";
for ($i = 1; $i <= count($incpath) - 1; $i++) {
  $incpath3 .= ":" . $incpath[$i];
}
$incpath3 = ".:/home2/username/includes/common:" . $incpath2 . $incpath3;
set_include_path($incpath3);

//From here to the end of this file, I set up error handling--thanks to a script from one of Larry Ulman's books.
// This script determines how errors are handled.

// Flag variable for site status:
if (! $live){
$live = TRUE;
//$live = FALSE;
}

date_default_timezone_set("America/New_York");

// Error log email address:
$webmaster_email = "doni-not-mobile@fusemail.com";
//'contactform@' . $servername[1] . "." . $servername[2];

// Create the error handler.
function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {

global $live, $webmaster_email, $incpath2;

if ($live){
$lineterm = "\n";
}else{
$lineterm = "<br />";
}
// Build the error message.
$message = "An error occurred in script '" . $e_file . "' on line " . $e_line . ": " . $lineterm . $e_message . $lineterm . $lineterm;

// Add the date and time.
$message .= "Date/Time: " . date('n-j-Y H:i:s') . $lineterm . $lineterm ;

$message .= "Include Path:  " .  get_include_path() . $lineterm . $lineterm;

$message .= "Files in " . $incpath2 . ": " .$lineterm;
if (file_exists($incpath2) && is_dir($incpath2)) {
if ($handle = opendir($incpath2 . "/")) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$message .= $file . $lineterm;
}
}
closedir($handle);
}
} else {
$message .= "The Folder " . $incpath2 . " does not exist." . $lineterm . $lineterm;
}


$message .= "$lineterm Files in common folder:" . $lineterm;
if (file_exists("/home2/donirela/includes/common") && is_dir("/home2/donirela/includes/common")) {
if ($handle = opendir("/home2/donirela/includes/common/")) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$message .= $file . $lineterm;
}
}
closedir($handle);
}
} else {
$message .= "The Folder '/home2/donirela/includes/common' does not exist." . $lineterm . $lineterm;
}
// Append $e_vars to the $message.
$message .= "<pre>" . print_r ($e_vars, 1) . "</pre>" . $lineterm;
if ($live) { // Don't show the specific error.
// error_log ($message, 1, $webmaster_email); // Send email.

$headers = "From:  " . $webmaster_email . "\r\n";
mail($webmaster_email, "PHP Error Message", $message, $headers);

// Only print an error message if the error isn't a notice.
if ($e_number != E_NOTICE) {
echo '<div id="Error">A system error occurred. We apologize for the inconvenience.  The webmaster has been notified of the error and will get it fixed ASAP.</div><br />';
}

} else { // Development (print the error).
echo '<div id="Error">' . $message . '</div><br />';
}

} // End of my_error_handler() definition.

// Use my error handler.
set_error_handler ('my_error_handler');
?>
[/code]

[code]
This is Header2.inc--it contains no PHP code.  It's all HTML content that sets up the page title, links the CSS file, and sets up all the common items that go across the top of all pages on the site.
[/code]

[code]
<?php
//This is the FRDBConnect.inc file.  The code in this file as you'd expect,
//opens the database connection.
if (!isset ($ignoreDB)){
$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dbname");
}


function disconnectDB(){
  mysql_close($dbc);
}

function escape_data($data){
global $dbh;
if (ini_get('magic_quotes_gpc')){
$data = stripslashes($data);
}
return $data;
}
?>
[/code]

[code]
This is footer.inc--it contains no PHP code.  It's all HTML content that puts the copyright info at the bottom of the page.
[/code]
Link to comment
Share on other sites

Well I had an epiphony (sp?) last night while I was in bed trying to go to sleep.

What was happening is that the old code REQUIRED that you type in the "www" when you visit the site.  If you didn't then it didn't add the needed folder to the include_path.

Thanks for taking a look.

I had to change the following
[code]
$servername = explode(".",$_SERVER['SERVER_NAME']); 
switch ($servername[1]) {
case 'site1':
  $incpath2 = "/home2/username/includes/site1";
  break;
case 'site2':
  $incpath2 = "/home2/username/includes/site2";
  break;
case 'site3':
  $incpath2 = "/home2/username/includes/site3";
  break;
}[/code]

to

[code]if (eregi ("site1", $_SERVER['SERVER_NAME'])){
  $incpath2 = "/home2/username/includes/site1";
}elseif(eregi ("site2", $_SERVER['SERVER_NAME'])){
  $incpath2 = "/home2/username/includes/site2";
}elseif(eregi ("site3", $_SERVER['SERVER_NAME'])){
  $incpath2 = "/home2/username/includes/site3";
}
[/code]
Link to comment
Share on other sites

Guest
This topic is now 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.