2

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.

3
  • And.... your file actually exists? Is it relative to header.php, or the document calling header.php? Commented Nov 8, 2011 at 2:09
  • Read the error messages and try to understand them. For example if a function like include_once() creates an error, read the manual page of that function: php.net/include_once - Then double check you're using the right input values (like the filename and the php configuration of the include path in this case) and try again. Commented Nov 8, 2011 at 2:12
  • my file exists on C:/xampp/htdocs/pspace/classes/authorizationUtils.php and i m including it through include_once "../classes/authorizationUtils.php"; in header, which is located at C:/xampp/htdocs/pspace/includes/header.php Commented Nov 8, 2011 at 2:21

1 Answer 1

2

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';
Sign up to request clarification or add additional context in comments.

2 Comments

@user1021350 I've updated my answer with some more information that might help even more
thanx. will try that that and get back :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.