include in php not working - php

<?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");

Related

PHP fatal error opening required file

I'm having problems debugging this php error. '/app/bootstrap.php' exists so not sure why I'm getting this error? Can anyone help? Thanks
[24-Mar-2017 10:42:50 Europe/London] PHP Warning: require_once(/app/bootstrap.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/example.com/index.php on line 2
[24-Mar-2017 10:42:50 Europe/London] PHP Fatal error: require_once(): Failed opening required '/app/bootstrap.php' (include_path='.:/Applications/MAMP/bin/php/php5.6.30/lib/php') in /Applications/MAMP/htdocs/example.com/index.php on line 2
The path /app/bootstrap.php looks like a root path ( and the root isn't your website root, but your Mac root directory).
Change require path to __DIR__ . '/app/bootstrap.php', it means to require a sccript that in /app/bootstrap.php relative to CURRENT directory.

ERRORS with INCLUDE_ONCE Global Variable PHP

I created a config file that has a variable I want to use as a constant.
<?php
$ROOT_PATH = 'C:/Users/me/Documents/app-qas.com/site';
?>
On a CLASS page where I want to use the variable I added the following before instantiating the CLASS:
include_once("config.php");
$root=$ROOT_PATH;
I made the appropriate scoping changes to the functions in my class as follows:
global $root;
include_once($root."/Library/API/database.inc.php");
When I run my app, it DOES perform all of the data connections it
is designed to do, BUT it STILL returns the following errors:
Warning: include_once(config.php): failed to open stream: No such file
or directory in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 5
Warning: include_once(): Failed opening 'config.php' for inclusion
(include_path='.;C:\php\pear') in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 5
Notice: Undefined variable: ROOT_PATH in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 6
Warning: include_once(/Library/API/database.inc.php): failed to open
stream: No such file or directory in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 112
Warning: include_once(): Failed opening
'/Library/API/database.inc.php' for inclusion
(include_path='.;C:\php\pear') in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 112
Warning: include_once(/Library/API/database.inc.php): failed to open
stream: No such file or directory in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 112
Warning: include_once(): Failed opening
'/Library/API/database.inc.php' for inclusion
(include_path='.;C:\php\pear') in
C:/Users/me/Documents/app-qas.com/site'\class\Posting.class.php on
line 112
If I comment out the include and hard code the $root it runs like before BUT it DOES NOT throw any errors:
#include_once("joblaunch.php");
#$root=$ROOT_PATH;
$root='C:/Users/me/Documents/app-qas.com/site';
I don't understand why it runs and throws errors when getting the variable from the config.php but runs and doesn't throw an error when hard coding the path.
if you define a constant instead of a variable, this problem should be solved,
definition
old:
$ROOT_PATH = 'C:/Users/me/Documents/app-qas.com/site';
new:
define('ROOT_PATH', 'C:/Users/me/Documents/app-qas.com/site');
usage
old:
$root=$ROOT_PATH;
new:
$root = ROOT_PATH;

Warning: include(dbconn.php): failed to open stream: No such file or directory

I have a site that I am have several issues with. I am not sure if the hosting company did changed something or the site was hacked. I hope this is OK as I have listed a list of errors when a user tries to register for the site. This is also happening when a user tries to use the search function, however in the search function the errors appear at the top and then the search results actually display below. The registration page does not show anything but the following errors.
Warning: include(dbconn.php): failed to open stream: No such file or directory in /home1/hoapres/public_html/users/register/index.php on line 26
Warning: include(dbconn.php): failed to open stream: No such file or directory in /home1/hoapres/public_html/users/register/index.php on line 26
Warning: include(): Failed opening 'dbconn.php' for inclusion (include_path='.:/opt/php54/lib/php') in /home1/hoapres/public_html/users/register/index.php on line 26
Warning: include(functions.php): failed to open stream: No such file or directory in /home1/hoapres/public_html/users/register/index.php on line 27
Warning: include(functions.php): failed to open stream: No such file or directory in /home1/hoapres/public_html/users/register/index.php on line 27
Warning: include(): Failed opening 'functions.php' for inclusion (include_path='.:/opt/php54/lib/php') in /home1/hoapres/public_html/users/register/index.php on line 27
Fatal error: Call to undefined function userText2Web() in /home1/hoapres/public_html/users/register/index.php on line 40
Without knowing your directory structure it is tricky to offer a precise answer, but the first thing I would do before trying to include files is to explicitly set your include path.
Assuming that the site root ( DOCUMENT_ROOT ) is /home1/hoapres/public_html and you have a folder for storing all your include files called includes, the path would be /home1/hoapres/public_html/includes
<?php
set_include_path( $_SERVER['DOCUMENT_ROOT'] . '/includes' );
if( !realpath( get_include_path() ) ) exit('Bad path');
/* Test to see what files exist perhaps */
print_r( glob( get_include_path() . '/*.*' ) );
/* Can you see the files you expect? */
include 'dbconn.php';
include 'functions.php';
?>
Your problem is include path you have used is not correct.
Please check your code where you have include the files like
include("dbconn.php");
you can try by this way
$fullpath = "http://yourdomain.com/";
if the dbconn.php is under any folder then
$fullpath = "http://yourdomain.com/foldername/";
include($fullpath."dbconn.php");

no such file or directory found in php

i have been trying to include the files using the code:
define('IN_PHPBB', true);
$phpbb_root_path='./../../';
$iai_root_path = "./";
include($phpbb_root_path.'extension.inc');
include($phpbb_root_path.'common.'.$phpEx);
include($iai_root_path.'includes/constants.'.$phpEx);
include($iai_root_path.'includes/load_functions.'.$phpEx);
I am getting the following error and i have been scratching my head for quite a while now ,don't know here am i going wrong
Warning: include(./../../extension.inc) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\alice\mods\iai\install.php on line 33
Warning: include() [function.include]: Failed opening './../../extension.inc' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\alice\mods\iai\install.php on line 33
Notice: Undefined variable: phpEx in C:\xampp\htdocs\alice\mods\iai\install.php on line 34
Does your phpbb install live here "C:\xampp\htdocs\alice\" ?
Should you infact set $phpbb_root_path='../../../';
I sorted this problem by writing my include statement by including a $_SERVER['DOCUMENT_ROOT']
include $_SERVER['DOCUMENT_ROOT'] . "includes/functions.php";
As for why this works, im not so sure.

How can I set an absolute path for include function in php above the working directory?

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

Categories