Jump to content

Problem With Config.inc.php


yrstruly
 Share

Recommended Posts

HalloI cant seem to let the script pick up the config.inc.php file or find it, althoug i have saved it in the same directory. When i remove the includes/config.inc.php script, just to test it hows the same error for the header and footer files.Can somebody have a look at it please!This the Error message:Warning: require_once(./includes/config.inc.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\exercise\index.php on line 10Fatal error: require_once() [function.require]: Failed opening required './includes/config.inc.php' (include_path='.;C:\xampp\php\pear\') in C:\xampp\htdocs\exercise\index.php on line 10Index.php code follows:<?php # Script 2.4 - index.php/** This is the main page.* This page includes the configuration file,* the templates, and any content-specific modules.*/// Require the configuration file before any PHP code:require_once ('./includes/config.inc.php');// Validate what page to show:if (isset($_GET['p'])) {$p = $_GET['p'];} elseif (isset($_POST['p'])) { // Forms$p = $_POST['p'];} else {$p = NULL;}// Determine what page to display:switch ($p) {case 'about':$page = 'about.inc.php';$page_title = 'About This Site';break;case 'this':$page = 'this.inc.php';$page_title = 'This is Another Page.';break;case 'that':$page = 'that.inc.php';$page_title = 'That is Also a Page.';break;case 'contact':$page = 'contact.inc.php';$page_title = 'Contact Us';break;case 'search':$page = 'search.inc.php';$page_title = 'Search Results';break;// Default is to include the main page.default:$page = 'main.inc.php';$page_title = 'Site Home Page';break;} // End of main switch.// Make sure the file exists:if (!file_exists('./modules/' . $page)) {$page = 'main.inc.php';$page_title = 'Site Home Page';}// Include the header file:include_once ('./includes/header.html');// Include the content-specific module:// $page is determined from the above switch.include ('./modules/' . $page);// Include the footer file to complete the template:include_once ('./includes/footer.html');?>Config.inc file follows:<?php # Script 2.1 - config.inc.php/** File name: config.inc.php* Created by: Larry E. Ullman of DMC Insights, Inc.* Contact: LarryUllman@DMCInsights.com, [www.dmcinsights.com]* Last modified: November 8, 2006** Configuration file does the following things:* - Has site settings in one location.* - Stores URLs and URIs as constants.* - Sets how errors will be handled.*/# ******************** ## ***** SETTINGS ***** #// Errors are emailed here.$contact_email = 'address@example.com';// Determine whether we're working on a local server// or on the real server:if (stristr($_SERVER['HTTP_HOST'], 'local') || (substr($_SERVER['HTTP_HOST'], 0, 7) =='192.168')) {$local = TRUE;} else {$local = FALSE;}// Determine location of files and the URL of the site:// Allow for development on different servers.if ($local) {// Always debug when running locally:$debug = TRUE;// Define the constants:define ('BASE_URI', '/path/to/html/folder/');define ('BASE_URL', 'http://localhost/directory/');define ('DB', '/path/to/mysql.inc.php');} else {define ('BASE_URI', '/path/to/live/html/folder/');define ('BASE_URL', 'http://www.example.com/');define ('DB', '/path/to/live/mysql.inc.php');}/** Most important setting...* The $debug variable is used to set error management.* To debug a specific page, add this to the index.php page:if ($p == 'thismodule') $debug = TRUE;require_once('./includes/config.inc.php');* To debug the entire site, do$debug = TRUE;* before this next conditional.*/// Assume debugging is off.if (!isset($debug)) {$debug = FALSE;}# ***** SETTINGS ***** ## ******************** ## **************************** ## ***** ERROR MANAGEMENT ***** #// Create the error handler.function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {global $debug, $contact_email;// Build the error message.$message = "An error occurred in script '$e_file' on line $e_line: \n<br />$e_message\n<br/>";// Add the date and time.$message .= "Date/Time: " . date('n-j-Y H:i:s') . "\n<br />";// Append $e_vars to the $message.$message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n<br />";if ($debug) { // Show the error.echo '<p class="error">' . $message . '</p>';} else {// Log the error:error_log ($message, 1, $contact_email); // Send email.// Only print an error message if the error isn't a notice or strict.if ( ($e_number != E_NOTICE) && ($e_number < 2048)) {echo '<p class="error">A system error occurred. We apologize for theinconvenience.</p>';}} // End of $debug IF.} // End of my_error_handler() definition.// Use my error handler:set_error_handler ('my_error_handler');# ***** ERROR MANAGEMENT ***** ## **************************** #?>

Link to comment
Share on other sites

The error message says that your script is in the "exercise" directory. require_once ('./includes/config.inc.php') tells the script to look for "config.inc.php" in the "includes" directory, which is also inside "exercise" directory. "./" refers to the current directory. If that is not the relationship between these files, then you need to pass a different path to require_once(). Maybe the "includes" directory is not in the same directory as your script? (Maybe you are confusing "./" for "../", which means "go up one directory" ?) Maybe "config.inc.php" is not in the "includes" directory? Maybe your server doesn't like files with more than one dot?

Link to comment
Share on other sites

where it calls the header and footer.html, i exactly saved my confic.inc.php file like that(in the same directory-includes). And it does recognise and read those files
No it doesn't:An error occurred in script 'C:\xampp\htdocs\exercise\includes\index.php' on line 63:include_once(./includes/header.html) [function.include-once]: failed to open stream: No such file or directoryCan you show us what your folder structure looks like? Edited by justsomeguy
Link to comment
Share on other sites

No it doesn't:An error occurred in script 'C:\xampp\htdocs\exercise\includes\index.php' on line 63:include_once(./includes/header.html) [function.include-once]: failed to open stream: No such file or directoryCan you show us what your folder structure looks like?
Im using the latest version of the xammp packageHi thanx for the help, my directory looks like this:htdocs/exercise/includes (here in the includes i have stored the index.php;config.inc.php;header.html and footer.html) .Can you see if i have done something wrong here and what do mean when you say:No it doesn't (read the html files). It displayes those codes(html)
Link to comment
Share on other sites

Since index.php is INSIDE the "includes" directory, the path to your include files should NOT contain the "includes" directory. When a file includes another file that is in the SAME directory, the include() statement only needs to name the file.What's happening now is that PHP is looking for a directory called "includes" that is inside the directory called "includes".In other words, try this:require_once(config.inc.php)ORuse your original statements, but move index.php up to the "exercise" directory. This would reflect the file/directory relationship you really wanted anyway.

Link to comment
Share on other sites

Since index.php is INSIDE the "includes" directory, the path to your include files should NOT contain the "includes" directory. When a file includes another file that is in the SAME directory, the include() statement only needs to name the file.What's happening now is that PHP is looking for a directory called "includes" that is inside the directory called "includes".In other words, try this:require_once(config.inc.php)ORuse your original statements, but move index.php up to the "exercise" directory. This would reflect the file/directory relationship you really wanted anyway.
Thank you for your help and patience with me, i really appreciate that. The index page dont show any errors. This might not be the right category to ask this, but i would like to know why my sidebare dont display to the right. I am working out of a book and im coping the codes exactly like they are.The text in the file just display like paragraphs, like im just lining them up and using page breaks.
Link to comment
Share on other sites

Thank you for your help and patience with me, i really appreciate that. The index page dont show any errors. This might not be the right category to ask this, but i would like to know why my sidebare dont display to the right. I am working out of a book and im coping the codes exactly like they are.The text in the file just display like paragraphs, like im just lining them up and using page breaks.
Hi one last thing id also like to know in connection with this template that im building. It has a main.inc.php and also a search.inc.php.When i save the main.inc.php like this:htdocs/exercise/modules/main.inc.php and run it in the browse--> http://localhost/exercise/modules.main.inc.php, it gives me this error message: Object not found!The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.If you think this is a server error, please contact the webmaster.Error 404localhost04/02/09 23:55:38Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i mod_autoindex_color PHP/5.2.8 I would like to know, is it supose to show this message when i run it like that. When i run the. http://localhost/exercise/index.phpThe template displays without any error message. Am i doing this correctly?The other file:search.inc.php, i saved in the exercise directory and not in the modules directory. I have tried to search the page and i cant say if it wokring or not. I do get an error message when i save this search.inc.php in the modules directory. The template displays only half the info then and it shows the following error:Parse error: parse error in C:\xampp\htdocs\exercise\modules\search.inc.php on line 51I have included the main.inc.php and search.inc.php:<?php # Script 2.5 - main.inc.php /* * This is the main content module. * This page is included by index.php. */ // Redirect if this page was accessed directly: if (!defined('BASE_URL')) { // Need the BASE_URL, defined in the config file: require_once ('./includes/config.inc.php'); // Redirect to the index page: $url = BASE_URL . 'index.php'; header ("Location: $url"); exit; } // End of defined() IF. ?> <h2>Welcome to Leaves.</h2> <p>Welcome to Leaves, a static, 3 column layout made with your usual CSS and XHTML. It isable to correctly accommodate any font size increases or shrinkages (Is that a word?). It seemsto work fine in Firefox, Opera, Internet Explorer and Safari. It's more minimal than otherdesigns, because I think images (drop shadows, giant header images) are being obsessively overused these days. I think it detracts from the content and shoves way too much information to aviewer all at the same time, so here you go: Leaves, a minimalist design. Feel free to massacreor change the design to your liking. Well, I guess it's time for some more Latin. <strong>If youwant me to create a custom design for you, feel free to drop me a line anytime atweb@smallpark.org </strong></p> <h2>Why I like Latin Filler Text. </h2> <p>Aenean eros arcu, condimentum nec, dapibus ut, tincidunt sit amet, urna. Quisqueviverra, eros sed imperdiet iaculis, est risus facilisis quam, id malesuada arcu nulla luctusurna. Nullam et est. Vestibulum velit sem, faucibus cursus, dapibus vestibulum, pellentesque et,urna. Donec luctus. Donec lectus. Aliquam eget eros facilisis tortor feugiat sollicitudin.Integer lobortis vulputate sapien. Sed iaculis erat ac nunc. <a href="#">Etiam eu enim.</a>Mauris ipsum urna, rhoncus at, bibendum sit amet, euismod eget, dolor. Mauris fermentum quamvitae ligula. Vestibulum in libero feugiat justo dictum consectetuer. Vestibulum euismod puruseget elit. Nunc sed massa porta elit bibendum posuere. Nunc pulvinar justo sit amet odio. In sedest. Phasellus ornare elementum nulla. Nulla ipsum neque, cursus a, viverra a, imperdiet at,enim. Quisque facilisis, diam sed accumsan suscipit, odio arcu hendrerit dolor, quis aliquetmassa nulla nec sem. </p> <h2>Because I just do. </h2> <p><a href="#">Proin sagittis leo in diam</a>. Vestibulum vestibulum orci vel libero. Crasmolestie pede quis odio. Phasellus tempus dolor eu risus. Aenean tellus tortor, dignissim sitamet, tempus eu, eleifend porttitor, ipsum. Fusce diam. Suspendisse potenti. Duis consequatscelerisque lacus. Proin et massa. Duis adipiscing, lectus a euismod consectetuer, pede liberoornare dui, et lacinia ipsum ipsum nec lectus. Suspendisse sed nunc quis odio aliquet feugiat.Pellentesque sapien. Phasellus sed lorem eu augue luctus commodo. Nullam interdum convallis nunc.Fusce varius. Ut egestas. Fusce interdum iaculis pede. Sed vehicula vestibulum odio. <ahref="#">Donec id diam. </a></p>Script 2.5 The first content module has the HTML for the main page. Some PHP code redirects the Web browser ifthis script was accessed directly.--------------------------------------------<?php # Script 2.6 - search.inc.php /* * This is the search content module. * This page is included by index.php. * This page expects to receive $_GET['terms']. */ // Redirect if this page was accessed directly: if (!defined('BASE_URL')) { // Need the BASE_URL, defined in the config file: require_once ('./includes/config.inc.php'); // Redirect to the index page: $url = BASE_URL . 'index.php?p=search'; // Pass along search terms? if (isset($_GET['terms'])) { $url .= '&terms=' . urlencode($_GET['terms']); } header ("Location: $url"); exit; } // End of defined() IF. // Print a caption: echo '<h2>Search Results</h2>'; // Display the search results if the form // has been submitted. if (isset($_GET['terms']) && ($_GET['terms'] != 'Search...') ) { // Query the database. // Fetch the results. // Print the results: for ($i = 1; $i <= 10; $i++) { echo <<<EOT <h4><a href="#">Search Result #$i</a></h4> <p>This is some description. This is some description. This is some description. This is somedescription.</p>\n EOT; } } else { // Tell them to use the search form. echo '<p class="error">Please use the search form at the top of the window to search thissite.</p>'; } ?> Edited by yrstruly
Link to comment
Share on other sites

htdocs/exercise/modules/main.inc.php and run it in the browse--> http://localhost/exercise/modules.main.inc.php, it gives me this error message
It looks like the URL has a dot where it should have a slash.
Parse error: parse error in C:\xampp\htdocs\exercise\modules\search.inc.php on line 51
That says there's an error on line 51, I only see 49 lines of code you posted.
Link to comment
Share on other sites

It looks like the URL has a dot where it should have a slash.That says there's an error on line 51, I only see 49 lines of code you posted.
HiThere is only 49 lines, i dont know why it gives that error.When i run the code in the browser:http://localhost/exercise/modules/main.inc.php .The following error apears.Warning: require_once(./includes/config.inc.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\exercise\modules\main.inc.php on line 12Fatal error: require_once() [function.require]: Failed opening required './includes/config.inc.php' (include_path='.;C:\xampp\php\pear\') in C:\xampp\htdocs\exercise\modules\main.inc.php on line 12
Link to comment
Share on other sites

It looks like the URL has a dot where it should have a slash.That says there's an error on line 51, I only see 49 lines of code you posted.
HiThere is only 49 lines, i dont know why it gives that error.When i run the code in the browser:http://localhost/exercise/modules/main.inc.php .The following error apears.Warning: require_once(./includes/config.inc.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\exercise\modules\main.inc.php on line 12Fatal error: require_once() [function.require]: Failed opening required './includes/config.inc.php' (include_path='.;C:\xampp\php\pear\') in C:\xampp\htdocs\exercise\modules\main.inc.php on line 12
Link to comment
Share on other sites

It's not pointing to the correct path. If you have a file inside /exercise/modules, and you're telling it to include ./includes/config.inc.php, the file it looks for is /exercise/modules/includes/config.inc.php, if that file doesn't exist you'll get that error.

Link to comment
Share on other sites

Hi one last thing id also like to know in connection with this template that im building. It has a main.inc.php and also a search.inc.php.When i save the main.inc.php like this:htdocs/exercise/modules/main.inc.php and run it in the browse--> http://localhost/exercise/modules.main.inc.php, it gives me this error message: Object not found!The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.If you think this is a server error, please contact the webmaster.Error 404localhost04/02/09 23:55:38Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i mod_autoindex_color PHP/5.2.8 I would like to know, is it supose to show this message when i run it like that. When i run the. http://localhost/exercise/index.phpThe template displays without any error message. Am i doing this correctly?The other file:search.inc.php, i saved in the exercise directory and not in the modules directory. I have tried to search the page and i cant say if it wokring or not. I do get an error message when i save this search.inc.php in the modules directory. The template displays only half the info then and it shows the following error:Parse error: parse error in C:\xampp\htdocs\exercise\modules\search.inc.php on line 51I have included the main.inc.php and search.inc.php:<?php # Script 2.5 - main.inc.php /* * This is the main content module. * This page is included by index.php. */ // Redirect if this page was accessed directly: if (!defined('BASE_URL')) { // Need the BASE_URL, defined in the config file: require_once ('./includes/config.inc.php'); // Redirect to the index page: $url = BASE_URL . 'index.php'; header ("Location: $url"); exit; } // End of defined() IF. ?> <h2>Welcome to Leaves.</h2> <p>Welcome to Leaves, a static, 3 column layout made with your usual CSS and XHTML. It isable to correctly accommodate any font size increases or shrinkages (Is that a word?). It seemsto work fine in Firefox, Opera, Internet Explorer and Safari. It's more minimal than otherdesigns, because I think images (drop shadows, giant header images) are being obsessively overused these days. I think it detracts from the content and shoves way too much information to aviewer all at the same time, so here you go: Leaves, a minimalist design. Feel free to massacreor change the design to your liking. Well, I guess it's time for some more Latin. <strong>If youwant me to create a custom design for you, feel free to drop me a line anytime atweb@smallpark.org </strong></p> <h2>Why I like Latin Filler Text. </h2> <p>Aenean eros arcu, condimentum nec, dapibus ut, tincidunt sit amet, urna. Quisqueviverra, eros sed imperdiet iaculis, est risus facilisis quam, id malesuada arcu nulla luctusurna. Nullam et est. Vestibulum velit sem, faucibus cursus, dapibus vestibulum, pellentesque et,urna. Donec luctus. Donec lectus. Aliquam eget eros facilisis tortor feugiat sollicitudin.Integer lobortis vulputate sapien. Sed iaculis erat ac nunc. <a href="#">Etiam eu enim.</a>Mauris ipsum urna, rhoncus at, bibendum sit amet, euismod eget, dolor. Mauris fermentum quamvitae ligula. Vestibulum in libero feugiat justo dictum consectetuer. Vestibulum euismod puruseget elit. Nunc sed massa porta elit bibendum posuere. Nunc pulvinar justo sit amet odio. In sedest. Phasellus ornare elementum nulla. Nulla ipsum neque, cursus a, viverra a, imperdiet at,enim. Quisque facilisis, diam sed accumsan suscipit, odio arcu hendrerit dolor, quis aliquetmassa nulla nec sem. </p> <h2>Because I just do. </h2> <p><a href="#">Proin sagittis leo in diam</a>. Vestibulum vestibulum orci vel libero. Crasmolestie pede quis odio. Phasellus tempus dolor eu risus. Aenean tellus tortor, dignissim sitamet, tempus eu, eleifend porttitor, ipsum. Fusce diam. Suspendisse potenti. Duis consequatscelerisque lacus. Proin et massa. Duis adipiscing, lectus a euismod consectetuer, pede liberoornare dui, et lacinia ipsum ipsum nec lectus. Suspendisse sed nunc quis odio aliquet feugiat.Pellentesque sapien. Phasellus sed lorem eu augue luctus commodo. Nullam interdum convallis nunc.Fusce varius. Ut egestas. Fusce interdum iaculis pede. Sed vehicula vestibulum odio. <ahref="#">Donec id diam. </a></p>Script 2.5 The first content module has the HTML for the main page. Some PHP code redirects the Web browser ifthis script was accessed directly.--------------------------------------------<?php # Script 2.6 - search.inc.php /* * This is the search content module. * This page is included by index.php. * This page expects to receive $_GET['terms']. */ // Redirect if this page was accessed directly: if (!defined('BASE_URL')) { // Need the BASE_URL, defined in the config file: require_once ('./includes/config.inc.php'); // Redirect to the index page: $url = BASE_URL . 'index.php?p=search'; // Pass along search terms? if (isset($_GET['terms'])) { $url .= '&terms=' . urlencode($_GET['terms']); } header ("Location: $url"); exit; } // End of defined() IF. // Print a caption: echo '<h2>Search Results</h2>'; // Display the search results if the form // has been submitted. if (isset($_GET['terms']) && ($_GET['terms'] != 'Search...') ) { // Query the database. // Fetch the results. // Print the results: for ($i = 1; $i <= 10; $i++) { echo <<<EOT <h4><a href="#">Search Result #$i</a></h4> <p>This is some description. This is some description. This is some description. This is somedescription.</p>\n EOT; } } else { // Tell them to use the search form. echo '<p class="error">Please use the search form at the top of the window to search thissite.</p>'; } ?>
HiIm still having problems with the main.inc.php. When i run it, it gives me this errors Warning: require_once(config.inc.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\exercise\modules\main.inc.php on line 12Fatal error: require_once() [function.require]: Failed opening required 'config.inc.php' (include_path='.;C:\xampp\php\pear\') in C:\xampp\htdocs\exercise\modules\main.inc.php on line 12This si the path:http://localhost/exercise/modules/main.inc.phpThe require code: require_once ('./includes/config.inc.php');
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...