Jump to content
Larry Ullman's Book Forums

[Solved] Site Works In Wamp, Require/includes Fail Live


Recommended Posts

Greetings,

 

I designed a site mostly following the first example in the book, and it works and looks great on my localhost; however, the script immediately fails when live, whether I use require or include for the config.inc.php file.

 

My index.php file looks like this, with some attempted debugging:

<?php
echo "./ is the current working directory, i.e. " . getcwd();
echo "<p>Attempting to require './includes/config.inc.php'</p>";

require './includes/config.inc.php'; // changing to include also fails

echo "Success!"; // does not print

// rest of code

// other includes work fine if I remove the first
// "require './includes/config.inc.php'"
include "./includes/header.html";

According to the output, my working directory for the live site is '/home/myname/public_html', which is where the index.php file and all my folders reside. Locally, the same files and folders are in 'C:\wamp\www\myfolder'.

 

I contacted my web host but all they could say is there must be an error in my php, but it fails on literally the very first require statement for reasons I cannot fathom.

 

Any suggestions?

 

Thanks for your help,

Brian

 

P.S: Larry, your book is great so far - I'm looking forward to part two!

EDIT: For completeness, here is the beginning of my config.inc.php file:

<?php	//=====This file should be included in every other file.======//

// prints locally, but not live, suggesting that the file is not found when live
// even though other files in the include directory can be found
echo "<p><br><br>Including config.inc.php</p>";

if (!defined('LIVE')) { DEFINE('LIVE', TRUE); } // Of course I change this as needed

DEFINE('BASE_URL', (LIVE ? 'http://mysite.net/' : '/mysite/'));

// rest of code
Link to comment
Share on other sites

Thanks for replying, Larry - no, there is not any error shown, just a completely blank page (unless I print debug statements before I attempt to require config.inc.php).

EDIT: <facedesk> oh man, this is embarrassing. Adding this:

 

ini_set('display_errors', 'On');
error_reporting(E_ALL);

revealed that I had misplaced a parenthesis in my config file, like " if (empty($var && ..."; interesting that this syntax error never caused any problems when used on my localhost, but there it is. Sorry to waste your time with such a plebeian mistake :P

 

 

I have other files in the includes directory that, if I don't try to include config.inc.php, are found just fine and display. If I hard-code all the entries instead of BASE_URL and such, everything works.

 

For example, the first line of php in my home view "require_once './includes/table_func.inc.php';" and the functions from that file work fine, but the first line of my index.php that tries to include the config.inc.php prevents the entire site from loading. I've checked and double-checked that the file exists, gave it 755 permissions, all to no avail, and I am unable to coax any error messages from it.

 

Thanks again for providing these help forums and taking the time to reply - I really appreciate it.

 

EDIT: To add more confusion to the mix, renaming the file to 'def.inc.php' allows it to be required by index.php! This means everything works, except I cannot require or include the same file in my contactform.php, not even once:

// contactform.php, located in root directory next to index.php
<?php
require_once "./includes/def.inc.php"; // causes a totally blank page like before
require_once "./includes/form_functions.inc.php"; // this one works if the above is commented out

// Create an empty error array if it doesn't already exist:
if (!isset($contact_errors)) { $contact_errors = array(); }

// rest of code

All the other views are routed through index.php using .htaccess rewrites, so they are able to use the def.inc.php values; contactform does NOT use the rewrite and is accessed directly, similar to index.php... I'm pretty new to web development, so I'm probably making some newbie mistake somewhere, but I have no idea what it could be.

 

 

Link to comment
Share on other sites

 Share

×
×
  • Create New...