Jump to content

cant connect to config.php using initialize.php in localhost


ricky spires

Recommended Posts

hello.

 

i want to create an oop website on my localhost but im having trouble getting the initialize file to find my config file.

 

if i point my browser to my local host my index page works fine because it does not need the initialize file at this stage, but if i point my browser to my admin index (http://localhost/djsonrotation/admin/) i get this error

 

Warning: require_once() [function.require-once]: URL file-access is disabled in the server configuration in /Applications/MAMP/htdocs/djsonrotation/includes/initialize.php on line 9

 

Warning: require_once(http://localhost/djsonrotation/config.php) [function.require-once]: failed to open stream: no suitable wrapper could be found in /Applications/MAMP/htdocs/djsonrotation/includes/initialize.php on line 9

 

Fatal error: require_once() [function.require]: Failed opening required 'http://localhost/djsonrotation/config.php' (include_path='.:/Applications/MAMP/htdocs/php5/lib/php') in /Applications/MAMP/htdocs/djsonrotation/includes/initialize.php on line 9

 

 

 

the initialize file is basically 1 place that points to lots of different places and mine looks like this:

<?PHP
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_DOMAIN') ? null : define('SITE_DOMAIN', 'http://localhost/djsonrotation');
defined('SITE_ROOT') ? null : define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT']);
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_DOMAIN.DS.'includes');
defined('CSS_PATH') ? null : define('CSS_PATH', SITE_DOMAIN.DS.'css');

require_once(SITE_DOMAIN.DS.'config.php');
require_once(SITE_DOMAIN.DS."functions.php");
require_once(SITE_DOMAIN.DS."session.php");
require_once(SITE_DOMAIN.DS."database.php");
require_once(SITE_DOMAIN.DS."user.php");
?>

 

this is the config file its looking for:

<?PHP
defined('DB_SERVER') ? null : define("DB_SERVER", "localhost");
defined('DB_USER') ? null : define("DB_USER", "admin");
defined('DB_PASS') ? null : define("DB_PASS", "*************");
defined('DB_NAME') ? null : define("DB_NAME", "djsonrotation");
?>

 

this is how my mamp is set up

PORTS - 80  - 3306

PHP - 5

APACHE - /Applications/MAMP/htdocs

 

 

this is where my file are located on my wwwroot

 

/index.php

/includes/initialize.php

/includes/config.php

/admin/index.php

 

 

this is the line of code calling the initialize on /admin/index.php

require_once("../includes/initialize.php");

 

 

thanks

rick

Link to comment
Share on other sites

It looks like you're calling the file using the domain path, and not the servers directory path.

 

defined('SITE_DOMAIN') ? null : define('SITE_DOMAIN', 'http://localhost/djsonrotation');
defined('SITE_ROOT') ? null : define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT']);
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_DOMAIN.DS.'includes');
defined('CSS_PATH') ? null : define('CSS_PATH', SITE_DOMAIN.DS.'css');

require_once(SITE_DOMAIN.DS.'config.php');

 

if you look, you can see that the require_once function is trying to call "http://localhost/djsonrotation/config.php" when you really need it to call the file relative to the hard drive location, and not relative to the domain location.

 

I would change that to:

 

defined('SITE_DOMAIN') ? null : define('SITE_DOMAIN', 'http://localhost/djsonrotation');
defined('SITE_ROOT') ? null : define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT']);
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_DOMAIN.DS.'includes');
defined('CSS_PATH') ? null : define('CSS_PATH', SITE_DOMAIN.DS.'css');

require_once(SITE_ROOT.DS.'includes/config.php');

Link to comment
Share on other sites

hello.

 

thanks for your replies.

 

i just tried this but it didnt work

 

<?PHP
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_DOMAIN') ? null : define('SITE_DOMAIN', 'http://localhost/djsonrotation');
defined('SITE_ROOT') ? null : define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT']);

require_once(SITE_ROOT.DS.'includes/config.php');
require_once(SITE_ROOT.DS."includes/functions.php");
require_once(SITE_ROOT.DS."includes/session.php");
require_once(SITE_ROOT.DS."includes/database.php");
require_once(SITE_ROOT.DS."includes/user.php");
?>

 

i got this error:

Warning: require_once(/Applications/MAMP/htdocs/includes/config.php) [function.require-once]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/djsonrotation/includes/initialize.php on line 7

 

Fatal error: require_once() [function.require]: Failed opening required '/Applications/MAMP/htdocs/includes/config.php' (include_path='.:/Applications/MAMP/htdocs/php5/lib/php') in /Applications/MAMP/htdocs/djsonrotation/includes/initialize.php on line 7

Link to comment
Share on other sites

Warning: require_once(/Applications/MAMP/htdocs/includes/config.php) [function.require-once]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/djsonrotation/includes/initialize.php on line 7

 

Fatal error: require_once() [function.require]: Failed opening required '/Applications/MAMP/htdocs/includes/config.php' (include_path='.:/Applications/MAMP/htdocs/php5/lib/php') in /Applications/MAMP/htdocs/djsonrotation/includes/initialize.php on line 7

 

Read the error:

 

/Applications/MAMP/htdocs/includes/config.php

 

that is where it is saying it's looking.

 

/Applications/MAMP/htdocs/djsonrotation/includes/initialize.php

 

That is where the script is.  So:

<?PHP
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_DOMAIN') ? null : define('SITE_DOMAIN', 'http://localhost/djsonrotation');
defined('SITE_ROOT') ? null : define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT']);

require_once(SITE_ROOT.DS.'djsonrotation/includes/config.php');
require_once(SITE_ROOT.DS."djsonrotation/includes/functions.php");
require_once(SITE_ROOT.DS."djsonrotation/includes/session.php");
require_once(SITE_ROOT.DS."djsonrotation/includes/database.php");
require_once(SITE_ROOT.DS."djsonrotation/includes/user.php");
?>

 

Try that.

Link to comment
Share on other sites

hello.

 

great. that seemed to work.

 

the only thing is, i have a new error. i will try a couple of things and if i cant get it working ill come back to you later.

 

thanks

bye for now :)

 

 

 

 

i tried it but no go

 

<?PHP
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_DOMAIN') ? null : define('SITE_DOMAIN', 'http://localhost/djsonrotation');
defined('SITE_ROOT') ? null : define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT']);


require_once(SITE_ROOT.DS.'djsonrotation/includes/config.php');
require_once(SITE_ROOT.DS."djsonrotation/includes/functions.php");
require_once(SITE_ROOT.DS."djsonrotation/includes/session.php");
require_once(SITE_ROOT.DS."djsonrotation/includes/database.php");
require_once(SITE_ROOT.DS."djsonrotation/includes/user.php");
?>

 

this is the new error :

 

Notice: Use of undefined constant LIB_PATH - assumed 'LIB_PATH' in /Applications/MAMP/htdocs/djsonrotation/includes/database.php on line 3

 

Warning: require_once(LIB_PATH/config.php) [function.require-once]: failed to open stream: No such file or directory in /Applications/MAMP/htdocs/djsonrotation/includes/database.php on line 3

 

Fatal error: require_once() [function.require]: Failed opening required 'LIB_PATH/config.php' (include_path='.:/Applications/MAMP/htdocs/php5/lib/php') in /Applications/MAMP/htdocs/djsonrotation/includes/database.php on line 3

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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