Jump to content

require_once(classes/Config.php): failed to open stream


Dianbr

Recommended Posts

Hi,

 

I hope someone can help. I am fairly new to php and have the following problem that I cannot get a solution for.

 

We are building a logon system for a website and are receiving the following error.

 

?>PHP Warning: require_once(classes/Config.php): failed to open stream: No such file or directory in C:\Domains\hellopoker.co.za\wwwroot\test\php\core\init.php on line 22 PHP Fatal error: require_once(): Failed opening required 'classes/Config.php' (include_path='.;C:\php\pear') in C:\Domains\hellopoker.co.za\wwwroot\test\php\core\init.php on line 22

 

 

Code for index.php

 

<?php

require_once 'core/init.php';

echo Config::get('mysql/host');

?>
 

Code for config.php

 

<?php

class Config{
    public static function get ($path = null){
        if ($path){
            $config = $GLOBALS['config'];
            $path = explore('/',$path);
            
            foreach($path as $bit){
                if(isset($config[$bit])){
                    echo 'Set';
                }
            }
        }
    }

}

?>

 

 

Code for init.php

 

 

<?php

session_start();

$GLOBALS['config'] = array(
    'mysql' => array(
        'mysql' => 'xxxxxxx',
        'username' => 'xxxxxx',
        'password' => 'xxxxxxx',
        'db' => 'xxxxxxx'
        ),
        'remember' => array(
            'cookie_name' => 'hash',
            'cookie_expiry' => 604800
        ),
        'session' => array(
            'session_name' => 'user'
        )
);

spl_autoload_register(function($class) {
    require_once 'classes/' . $class . '.php';
});

?>



?>

 

 

Any help will be greatly be appreciated.

 

 

Link to comment
Share on other sites

Use relative URLs, depending on where the classes directory lies in your structure, you could do the following:

spl_autoload_register(function($class) {
    require_once ($_SERVER['DOCUMENT_ROOT'] . '/classes/' . $class . '.php');

});

 

From your error you can see that your autoloader can't find the file to include.

Edited by IanA
Link to comment
Share on other sites

Hard to follow this bunch of code, but the error is pretty self-explanatory.  You are trying to find a file that is just where you think it is.  The message pinpoints the line with the problem, use the info provided to check your file system to see that the reference is accurate.

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.