i am using this code to define the directory paths of my project:
config.php is
<?php
define('CB_HOME', realpath(dirname(__DIR__)));
define('FD_HOME', CB_HOME."/testbot");
I use am using CB_home And FD_home in other files.
i am getting the error:
PHP Notice: Use of undefined constant CB_HOME - assumed 'CB_HOME' in C:\\xampp\\htdocs\\test-bot\\testbot\\bootstrap.php on line 3
PHP Warning: require_once(CB_HOME/AbstractCbRest.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in C:\\xampp\\htdocs\\test-bot\\testbot\\bootstrap.php on line 3
PHP Fatal error: require_once() [<a href='function.require'>function.require</a>]: Failed opening required 'CB_HOME/AbstractCbRest.php' (include_path='.;C:\\xampp\\php\\PEAR') in C:\\xampp\\htdocs\\test-bot\\testbot\\bootstrap.php on line 3
my bootstrap.php is :
<?php
require_once 'config.php';
require_once CB_HOME.'/AbstractCbRest.php';
where is it going wrong?
My guess is that include_path settings are interfering with your script. So (as mentioned by #deceze) you might be loading an incorrect (although existing) config.php file.
Maybe you could try using an absolute path to include your configuration or use something along the lines of:
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config.php';
It is obvious that the windows path with two "\" doesn't work. To remove a double backslash (NOTE: this is no solution but a workaround), do this:
$someValue = 'C:\\xampp\\htdocs\\test-bot\\testbot\\'; $someValue = preg_replace('/\\\\/u', '\\', $someValue);
or in your case:
define('CB_HOME', preg_replace('/\\\\/u', '\\', realpath(dirname(DIR))));
Related
Hello i'm running WAMP (32 Bit) server
i exec C:\wamp\www\1\index.php using browser with this address http://localhost:8080/1/
index.php has the follow code
require_once 'libraries/database/database.php';
database.php has the follow code
require_once '../misc/traits/singleton.php';
singleton.php is located in this location
C:\wamp\www\1\libraries\misc\traits\singleton.php
database.php is located in this location
C:\wamp\www\1\libraries\database\database.php
and there is error(s):
( ! ) Warning: require_once(../misc/traits/singleton.php): failed to open stream: No such file or directory in C:\wamp\www\1\libraries\database\database.php on line 3
( ! ) Fatal error: require_once(): Failed opening required '../misc/traits/singleton.php' (include_path='.;C:\php\pear') in C:\wamp\www\1\libraries\database\database.php on line 3
Thanks
Paths stem from the php file that was originally executed, unless you change the path using chdir.
So use 'libraries/misc/traits/singleton.php'
If you want to do relative includes, use __DIR__, which is the directory of the CURRENT file.
e.g.
__DIR__ . '/../misc/traits/singleton.php'
I'm new to PHP and I need to use some classes from an external library in my project.
My .php file, SMMain.php is in /Library/WebServer/Documents directory on my Mac. I placed the classes from the outside library right there next to it. All of these files are from the namespace Parse;. Some of the classes are in a directory called Internal.
No matter what require_once I try I get errors that the files are not found. Here's what I tried:
require_once('\Internal\Encodable.php');
produces this error:
Fatal error: require_once(): Failed opening required '\Internal\Encodable.php' (include_path='.:') in /Library/WebServer/Documents/SMMain.php on line 13
Next try:
require_once('/Internal/Encodable.php');
produces this:
Fatal error: require_once(): Failed opening required '.php' (include_path='.:') in /Library/WebServer/Documents/SMMain.php on line 7
I also tried:
require_once(realpath($_SERVER["DOCUMENT_ROOT"]) .'/Internal/Encodable.php');
Gives no error for the /Internal/Encodable file, but this produces another error:
Fatal error: Class 'ParseObject' not found in /Library/WebServer/Documents/SMMain.php on line 24
ParseObject.php is in the root directory together with my SMMain.php. So I tried requiring it like this:
require_once(realpath($_SERVER["DOCUMENT_ROOT"]) . '/ParseObject.php');
which gives this error:
Fatal error: Class 'ParseObject' not found in /Library/WebServer/Documents/SMMain.php on line 24
and if I try this:
require_once(realpath($_SERVER["DOCUMENT_ROOT"]) . 'ParseObject.php');
the error is:
Fatal error: require_once(): Failed opening required '/Library/WebServer/DocumentsParseObject.php' (include_path='.:') in /Library/WebServer/Documents/SMMain.php on line 17
So what's the solution?
Use require_once($_SERVER["DOCUMENT_ROOT"] .'/Internal/Encodable.php'); if the Internal directory is under the server document root and the Encodable.php is in there.
You can use the echo getcwd(); to see, where is the current working directory.
I am always doing that, when i call my index.php file (it handles all other files), to determinate, where is my base path, and store it in a constant. So lately, i will always include files with that path as an absolute path.
I need to include a file in php so I do
$web_proc = '../res/proc'; //variable read from config file I can't change
//in my file
include_once($web_proc . '/check_sprache.php');
and PHP outputs:
Warning: include_once(../res/proc/check_sprache.php): failed to open
stream: No such file or directory in
/Users/user/Sites/site/res/pdf/rechnung.php on line 62
Warning:
include_once(): Failed opening '../res/proc/check_sprache.php' for
inclusion (include_path='.:') in
/Users/user/Sites/site/res/pdf/rechnung.php on line 62
So I change the include path:
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__DIR__) . DIRECTORY_SEPARATOR);
and try it again, but PHP outputs:
Warning: include_once(../res/proc/check_sprache.php): failed to open
stream: No such file or directory in
/Users/user/Sites/site/res/pdf/rechnung.php on line 62
Warning:
include_once(): Failed opening '../res/proc/check_sprache.php' for
inclusion (include_path='.::/Users/user/Sites/site/res/') in
/Users/user/Sites/site/res/pdf/rechnung.php on line 62
But if if I do
include_once(dirname(__DIR__). DIRECTORY_SEPARATOR . $pfadweb_proc . '/check_sprache.php');
it works. But this is no solution, since the included file includes more files with a relative path, so they are alse not found.
So either I misunderstand the PHP include path, or it's just trolling me.
Can anybody help?
The include path looks odd in the second example; You have two PATH_SEPARATOR characters and a trailing DIRECTORY_SEPARATOR though I doubt this is the problem.
Try this one out instead
set_include_path(implode(PATH_SEPARATOR, [ // use array() if PHP < 5.4
dirname(__DIR__), // this should be /Users/user/Sites/site/res
get_include_path()
]));
include_once 'proc/check_sprache.php';
This will add the parent directory (/Users/user/Sites/site/res) of the CWD (/Users/user/Sites/site/res/pdf) to your include path.
Any include statements in any other files can use a relative path from /Users/user/Sites/site/res.
<?php
include("/Crypt/RSA.php");
$rsa = new Crypt_RSA();
$token=base64_decode("iKmHdK3ChRBPAU/I/wTKld4up91TMrcWjkE+VGggVryRzvhKC6l+sZ3F+j+qyW8rxg01/uu2E3z6aVirwmQ0ig==");
$private=base64_decode("MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAyUFH4OJOUOKh38raMxiQhmtuNSMxcznSdt9fWiJZOYpnv1rbu3h/heNCIOxOHSrlMz8FAKAW6rd9ddXNcm4myQIDAQABAkEApGbPcMVtdGWuFkJ/PH40kZnwzTeSja4OX0zZd6fXe0hBZZjA1nREuLGh2x7OXkpArytgQ35W2NHCxeldniTmgQIhAO7SB0Mhb/HLst4ty6HT2kZoAC/N2UdsBtQFdC8sNNxXAiEA17t4cVsx5EYYFifDSUwawz5pJSfrQYk1C0H1atL9Id8CIQDOtJL8k7BkxD5o95JM2yUN02518eGiY+n1EVNikQyfuQIgdph88fQsTU2rWCKr3NOVstfQfbigP/rpyjKMdBlhRwkCIE/x13OF2JUHlA5DqxCVh3LHMDDowr7SkQ2QVkqfBcAb");
$rsa->loadKey($privateKey);
echo $rsa->decrypt($cipher);
?>
i kept my include_path as .:/usr/local/lib/php
i am getting errors like this:
Warning: include(/Crypt/RSA.php) [function.include]: failed to open stream: No such file or directory in /home/futureti/public_html/reg2.php on line 2
Warning: include() [function.include]: Failed opening '/Crypt/RSA.php' for inclusion (include_path='.:/usr/local/lib/php') in /home/futureti/public_html/reg2.php on line 2
Fatal error: Class 'Crypt_RSA' not found in /home/futureti/public_html/reg2.php on line 3
Try this:
include('../Crypt/RSA.php');
Your current leading / is creating an absolute link, so going right back to your root directory.
../ means one folder up.
Try using the document root variable:
$doc_root = $_SERVER['DOCUMENT_ROOT'];
include($doc_root . "/Crypt/RSA.php");
I am running a script from
/wp-content/themes/currenttheme/chat.php
I want to include in the above php another one located in
/forum/chat/index.php
The index.php includes its own files
I already tried
$root = $_SERVER['DOCUMENT_ROOT'];
include($root."/forum/chat/index.php");
but I get this error
Warning: require(D:/My Dropbox/xampp/htdocs/lib/custom.php) [function.require]: failed to open stream: No such file or directory in D:\My Dropbox\xampp\htdocs\forum\chat\index.php on line 17
Fatal error: require() [function.require]: Failed opening required 'D:/My Dropbox/xampp/htdocs/lib/custom.php' (include_path='.;\My Dropbox\xampp\php\PEAR') in D:\My Dropbox\xampp\htdocs\forum\chat\index.php on line 17
(the index.php also includes some files, but the /forum/chat is ommited somehow in the path)
then I tried
$path = getcwd();
$myfile = "/forum/chat/index.php";
include ($path.$myfile);
and got this error:
Warning: include(D:\My Dropbox\xampp\htdocs\forum/forum/chat/index.php) [function.include]: failed to open stream: No such file or directory in D:\My Dropbox\xampp\htdocs\wp-content\themes\currenttheme\chat.php on line 24
Warning: include() [function.include]: Failed opening 'D:\My Dropbox\xampp\htdocs\forum/forum/chat/index.php' for inclusion (include_path='.;\My Dropbox\xampp\php\PEAR') in D:\My Dropbox\xampp\htdocs\wp-content\themes\currenttheme\chat.php on line 24
There is no problem with index.php. It is being included.
The error message says about custom.php file
Just use the same $_SERVER['DOCUMENT_ROOT'] technique for the custom.php
you have to add /forum/chat manually as there is no path to be omitted
Something wrong with:
include('../../../forum/chat/index.php');
?
There are all sorts of reasons why the code you've published will fail.
C.
use this.
require_once(ABSPATH.'forum/chat/index.php');
here ABSPATH = WordPress physical root directory path with trailing slash