ini_set include_path not working - php

It seems something on my server has been changed, and I'm seeing the inclusion failed error message on my every website on the server, here is one example:
Warning: require(xconstants_fa.php) [function.require]: failed to open stream: No such file or directory in /home/blahblah/public_html/fa/companies/ads/index.php on line 26
And in line 26 it says:
ini_set ("include_path", "../../includes/");
require "xconstants_fa.php";
So it's obvious that somehow my server has stopped using the "ini_set" function(because it was just working fine before), I looked into php.ini disable_functions, nothing is there, I commented all the disabled functions and also the open_basedir, not working there.
and if I:
ini_set ("include_path", "../../includes/") or die('ERROR HERE');
It echos ERROR HERE on the page
What's happening here? I would appreciate any kind of help.

Try using the actual function to change the include_path set_include_path():
$path = '../../includes/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

<?php ini_set('include_path',ini_get('include_path').':../../includes/:'); ?>

Related

Trouble with path for require function in PHP with o2switch host

I have uploaded website to o2switch host.
When I worked on localhost, all worked well.
But on o2switch, I have this error :
Warning: require_once(models/shopManager.class.php): failed to open stream: No such file or directory in /home/myUserNameo2switch/myDomain.fr/controllers/ShopController.controller.php on line 2
Fatal error: require_once(): Failed opening required 'models/shopManager.class.php' (include_path='.:/opt/alt/php73/usr/share/pear') in /home/myUserNameo2switch/myDomain.fr/controllers/ShopController.controller.php on line 2
I use MVC model with file structure like :
index.php
-controllers
-ShopController.controller.php
-models
-shopManager.class.php
In my index.php I do :
require_once "controllers/ShopController.controller.php";
$shopController = new ShopController();
In ShopController.controller.php, I do :
require_once "models/shopManager.class.php";
On o2switch PHP setting (I think similar to php.ini) there is configuration for include_path equal to .:/opt/alt/php73/usr/share/pear
The trouble is it coming from include_path value ?
That's the first time I work on online website and my first question here. Sorry if I am clumsy. Thank you
In ShopController.controller.php, you can try to change
require_once "models/shopManager.class.php";
to
require_once "../models/shopManager.class.php";
to see if the error message would disappear.
Thanks ild flue for your answer. It doesn't work.
My trouble is fixed. I had a trouble with capital and not capital letter between file and file called on require_once... :(
The most surprising is I had no error on local.

Get FATAL ERROR on include_once by switching to php 7.2.19

I switched to the last php 7.2.19 version and then I get Errors on includes as include_once where everything was ok before
PHP Warning: include_once(): Failed opening
'/home/xxx/domains/xxx.xxx/public_html/inc/smarty/libs/plugins/shared.make_timestamp.php'
for inclusion
The absolute path is correct and the file exists. How this can happen? For which reasons? Some others includes are ok, if I test the same path in other code, it works fine. Crazy

required_once issue in Google API Client for PHP

I have been trying to import/include file in my php script file and somehow it is not working. I know this require_once question has been asked so many times [ 1. require_once with subfolders , 2. require_once() cant find the include path, 3. Using require_once for up directory not working] but none of them seemed to be working for me.
Blow picture will explain what I am trying to do clearly:
What I tried and errors:
Attempt 1
require_once(__DIR__.'GoogleClientApi/src/Google/Service/Analytics.php');
echo 'Hey1'; //Does not echo this, means something went wrong above.
require_once(__DIR__.'GoogleClientApi/src/Google/Client.php');
echo 'Hey2';
Error I get:
Attempt 2 (Fixed issue of attempt 1 but raised another issue.)
So I decided to use absolute path :
include '/Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php';
echo 'Hey1';
include '/Applications/MAMP/htdocs/GoogleClientApi/src/Google/Service/Analytics.php';
echo 'Hey2';
Gives me error in Client.php file:
`Warning: require_once(/Google/Auth/AssertionCredentials.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php on line 18`
`Fatal error: require_once(): Failed opening required '/Google/Auth/AssertionCredentials.php' (include_path='.:/Applications/MAMP/bin/php/php5.5.10/lib/php') in /Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php on line 18`
Investigating upon I found Client.php (of Google APIs Client Library for PHP) has these lines which are actually present:
require_once 'Google/Auth/AssertionCredentials.php'; // <-- Can't find
require_once 'Google/Cache/File.php'; // <-- Can't find
require_once 'Google/Cache/Memcache.php'; // <-- Can't find
I do not what is going wrong here. Fixed attempt 1's issue but now errors are in google's own library which I do not know how to overcome. I assume I am doing something silly which I can not figure out. Any help or suggestion will be appreciated.
Did you ever dumped __DIR__? Usually there's no / at the end. So you would have to change your code to this:
require_once(__DIR__.'/GoogleClientApi/src/Google/Service/Analytics.php');
^
I just checked in your screen shot with the error message, there's no / at the end.
/Applications/MAMP/htdocsGoogleClientApi/src/Google/Client.php
instead of /Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php
It turns out I had to set the include path to include the root directory (src folder) using this line :
set_include_path("/Applications/MAMP/htdocs/GoogleClientApi/src/");
This worked for me in Client.php
set_include_path(__DIR__.'/../' . PATH_SEPARATOR . get_include_path());

require_once can't find file on webserver but works on localhost

All,
I have the following files:
builder.php
Oauth.php
twitteroauth.php
Within my builder.php page I have the following code:
require_once('twitteroauth.php');
Then in my twitteroauth.php page I have the following code:
require_once('OAuth.php');
All of these files are in the following path: wp-content/themes/alyeska/framework/frontend/functions
I'm testing this on my localhost and it works fine. However, when I upload all of these files to my webserver I get the following error message:
Warning: require_once(OAuth.php) [function.require-once]: failed to open stream: No such file or directory in /home/arokyne/website.com/wp-content/themes/alyeska/framework/frontend/functions/twitteroauth.php on line 10
Fatal error: require_once() [function.require]: Failed opening required 'OAuth.php' (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/arokyne/website.com/wp-content/themes/alyeska/framework/frontend/functions/twitteroauth.php on line 10
I'm not sure why I'm getting these errors since it works on my localhost. Can anyone point me in the right direction on how to fix this issue?
Thanks!
Two things jump to mind- make certain your path is correct, including the case sensitivity; also, make certain that the permissions on the file allow for the php server to read the file. A 644 mode should be sufficient, I believe; but, worst case, a 755 would definitely work.
And finally you may want to check whether your include path is correct.

error with using include_once in php

I have a file header where i have created variables for all the paths i need, like this:
$GLOBAL_stylePath = "http://localhost/pspace/css/";
(if i shouldn't use http in the above, then how would it be? C://htdocs/xampp/pspace/css/ ???)
include_once "/classes/authorizationUtils.php";
$authorizationUtils = new AuthorizationUtils();
anyways, the includes are messing up everything and giving me errors such as:
Warning: include_once() [function.include-once]: http:// wrapper is disabled in the server configuration by allow_url_include=0 in C:\xampp\htdocs\pspace\includes\header.php on line 12
how can i enable this configuration in my php.in. i have a variable allow_url_include=off, when i "on" it, no changes happen. and also this:
Warning: include_once() [function.include]: Failed opening 'http://localhost/pspace/classes/authorizationUtils.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\pspace\includes\header.php on line 12
Make sure that you editing the correct php.ini file. Usually there are two php.ini files associated with your installation. One is used for the command line interface php and the other for the server side php. Make sure that you make the changes to both.
Make sure that you restart your webserver after these changes are made.
This warning :
Warning: include_once() [function.include]: Failed opening 'http://localhost/pspace/classes/authorizationUtils.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\pspace\includes\header.php on line 12
it means that you try to include file which could not be found in include_path. So, what you need is to define your include_path.
If your directory listing is like this :
c:\xampp\htdocs\pspace\ // as your root
c:\xampp\htdocs\pspace\includes\
c:\xampp\htdocs\pspace\classes\
Try this :
<?php
$path1 = '.\includes\';
$path2 = '.\classes\';
set_include_path(get_include_path() . PATH_SEPARATOR . $path1 . PATH_SEPARATOR . $path2);
?>
Your also can change relative path $path1 = '.\includes\'; to absolute path $path1 = 'c:\xampp\htdocs\pspace\includes\';
Read this to understand more about set_include_path and about include function that always include files based on file path given. Hope this can help.

Categories