how to configure xampp for php to include files

16,581

My guess is that header.php is itself included from another file.

The . in PHP's default include path only refers to the called script. Picture it as the one at the top of the include tree. This file defines the include path root for relative includes.

If you want to include a file relative to the one doing the including, specify an absolute path using one of the magic constants available.

For example,

// PHP >= 5.3
include_once __DIR__ . '/../classes/authorizationUtils.php';

// PHP < 5.3
include_once dirname(__FILE__) . '/../classes/authorizationUtils.php';

An even better solution is to specify your application's include paths explicitly. So assuming you have some sort of globally included file (config.php / bootstrap.php / whatever) ...

define('APPLICATION_PATH', __DIR__);
// this is just an example, assuming this file exists at
// C:/xampp/htdocs/pspace/

set_include_path(implode(PATH_SEPARATOR, array(
    APPLICATION_PATH . '/includes',
    APPLICATION_PATH . '/classes',
    // enable the below line if you actually need the default include path, eg for PEAR
    // get_include_path()
)));

Then, from any other file (assuming it's included the above bootstrapping)

include_once 'authorizationUtils.php';
Share:
16,581
Nader Khan
Author by

Nader Khan

Updated on June 16, 2022

Comments

  • Nader Khan
    Nader Khan almost 2 years

    I am trying to include files in php, but everytime, its throwing me this error:

    Warning: include_once(authorizationUtils.php) [function.include-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\pspace\includes\header.php on line 13
    
    Warning: include_once() [function.include]: Failed opening 'authorizationUtils.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\pspace\includes\header.php on line 13
    
    Fatal error: Class 'AuthorizationUtils' not found in C:\xampp\htdocs\pspace\includes\header.php on line 15
    

    unable to find resources on this online. whether i should configure my xampp in any way, or do what, not sure.

  • Phil
    Phil over 12 years
    @user1021350 I've updated my answer with some more information that might help even more
  • Nader Khan
    Nader Khan over 12 years
    thanx. will try that that and get back :)