Link to home
Start Free TrialLog in
Avatar of William-B
William-B

asked on

require_once Path Error in PHP and Apache

I'm developing a moderately sized website using Dreamweaver CS4 and I've run into a problem with PHP and Apache.  I'm using the most current release versions of each program and I've divided my site into folders primarily for organization.  The problem is that if I have any php files that include php files that include other php files if the base php files are located in a sub directory the includes usually work but in the site root Apache complains in the error log that the files being included in the first included file cannot be found. I've included the relevant PHP files but cut out all the html and php functions to keep them reasonably sized.  The default.php is the default page that opens up when the site is typed in, rotator.php is a php file that include functions for a banner ad type system, and the connBDBannerAds.php is the automatically generated MySQL connection file by Dreamweaver.  Dreamweaver is just fine with all the links but Apache outputs this when it runs:

[Fri May 22 22:42:10 2009] [error] [client 127.0.0.1] PHP Warning:  require_once(../Connections/connBDBannerAds.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\web test\\PHP\\rotator.php on line 1
[Fri May 22 22:42:10 2009] [error] [client 127.0.0.1] PHP Fatal error:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required '../Connections/connBDBannerAds.php' (include_path='.;C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\web test') in C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\web test\\PHP\\rotator.php on line 1

I'm using relative links right now but I've also tried site root ones as well where Dreamweaver changes all the require_once lines with virtual.  I also tried prefixing all the paths with / to make it use the site root but that didn't work either.  
This is my first post so if I forgot to put something in or put too much in please let me know.  Thanks in advance for your time.
default.php
<?php require_once('Connections/connBDCustomers.php'); ?>
<?php require_once('PHP/rotator.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) 
{
     .... Other php stuff ....
}
?>
HTML Body
--------------------------------------------------------------------------------
rotator.php
<?php require_once('../Connections/connBDBannerAds.php'); ?>  <-Problem Here I think
<?php
function rotator()
{
	
}
?>
----------------------------------------------------------------------------------
connBDBannerAds.php
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connBDBannerAds = "localhost";
$database_connBDBannerAds = "bdbannerads";
$username_connBDBannerAds = "root";
$password_connBDBannerAds = "test";
$connBDBannerAds = mysql_pconnect($hostname_connBDBannerAds, $username_connBDBannerAds, $password_connBDBannerAds) or trigger_error(mysql_error(),E_USER_ERROR); 
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Todd Mummert
Todd Mummert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of William-B
William-B

ASKER

Thanks for your  quick response I had set the include directory to point to the site root pretty much, so i took out all of the ../ and / in the require statements and that seems to work just fine.  I had done that before, but it messes up all the recordset and other server behaviors in Dreamweaver so I had undone it thinking I messed something up.  Do you know of anyway to make it so Dreamweaver recognizes custom include paths for php scripts?  At any rate what you suggested did solve my problem, which I appreciate very much so I'm just going to mark this as solved.
Thank you for your prompt solution.  It worked great.