Include Path issue with config and header - php

I have a problem with include path in PHP.
Code:
https://github.com/kukubaczek/KukuShop/blob/master/www/panel/index.php
If i open the panel/index.php page I see this error's:
Warning: require_once(/parts/header.php): failed to open stream: No
such file or directory in /PATH/KukuShop/www/panel/index.php on line 3
Fatal error: require_once(): Failed opening required
'/parts/header.php' (include_path='/..') in
/PATH/KukuShop/www/panel/index.php on line 3
How can I fix this? Here is problem with include path.

You are using absolute references when you probably want relative file locations. Try using this instead:
require_once("../parts/header.php")

What does the directory structure look like?
The set_include_path('/..'); statement doesn't seem to make sense.
Your PHP installation can't seem to find the files.

Related

Include php file

I have the following directory tree on a linux server:
/home/control-center/back-office/php/average.php
/home/control-center/front-office/db.php
db.php contains the database connection information.
When I try to execute average.php, I get the following error message:
PHP Warning: include(../../front-office/db.php): failed to open stream: No such file or directory in /home/control-center/back-office/php/average.php on line 18
PHP Warning: include(): Failed opening '../../front-office/db.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/control-center/back-office/php/average.php on line 18
Should I include something else in my script so it would work? I found a couple of similar cases on the Internet, but I haven't managed to make it work.
Try include dirname(__FILE__) . '/../../front-office/db.php';
dirname(__FILE__) returns the absolute path of the current file. This ensures that you get the correct path relative to the current file.
Your problem is often encountered when the current script was included by another script. You can check this answer which is related to what I mentioned.
How do you include these 2 pages in your avarage.php file?
if you want to include header.php in index.php page which is in "sample" folder (sample/index.php) and header.php in include/header.php, then you have to write "../" before including a directory, so that would be like:
include '../include/header.php';

php configuration error

My php files were working fine but today when i check them i get following errors.
Warning: require_once(Connections/deal.php) [function.require-once]: failed to open stream: No such file or directory in C:\complete project\ordering system\orderingcart.php on line 1
Fatal error: require_once() [function.require]: Failed opening required 'Connections/orders.php' (include_path='.;C:\php\pear') in C:\complete project\orderingcart.php on line 1
I don't know how to resolve these errors, where do I start?
It means, the path you gave in require_once() is invalid. You have two options,
1.Checkout whether the path Connections/deal.php is correct or not. Do you have a folder Connections in the folder where this running file is placed? Is there a deal.php inside that folder Connections?
I think your running file path is C:\complete project\ordering system\orderingcart.php. It does not have such a folder and file. So place your Connections folder in C:\complete project\ordering system\ and checkout.
2.Else, You can run the page without fatal error if you change the line to include_once(Connections/deal.php). Functions assosciated with deal.php will be inactivated.
This sounds like the file has either moved OR the file permission have been altered as to prevent the server account (usually www-data) from having access to it.
You might also have better luck by trying to access the file by suppling an absolute path, rather than a relative path, e.g:
<?php
$lines = file("C:\\Documents and Settings\\myfile.txt");
foreach($lines as $line){
echo($line);
}
?>
This file path issue give full file location like
if it is windows
require_once('C:/complete project/Connections/deal.php');
For reference
http://php.net/manual/en/function.realpath.php

File is not including and require

I include a file in my php document but on local side and on server side it is not including i use require but it is also not working and an error show on the screen.. I checked the path 100 times it is right. The error is this:
Warning: require(../library/config.php) [function.require]: failed to open stream: No such file or directory in /home/logics/public_html/clients/creativecellutions/farnelo/files/header.php on line 3
Warning: require(../library/config.php) [function.require]: failed to open stream: No such file or directory in /home/logics/public_html/clients/creativecellutions/farnelo/files/header.php on line 3
Fatal error: require() [function.require]: Failed opening required '../library/config.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/logics/public_html/clients/creativecellutions/farnelo/files/header.php on line 3
Please help me to resolve this.
This is my code:
<?php
require ("../library/config.php");
require ("../library/functions.php");
?>
require(../library/config.php)
Is pointing to the wrong location in your directory. Get the location of config.php relative to the position of the file this script is calling. That should resolve the error.
your code will try to include a file located at
/home/logics/public_html/clients/creativecellutions/farnelo/library/config.php
are you sure that is the currect location of the file?
if it is then the only ussue possible is that you do not have permission to read the file with php.
I guess you are not directly running clients/creativecellutions/farnelo/files/header.php and including this in some other file index.php or something else and that's where the problem may be.
Try using relative path require_once( dirname(__FILE__) . '/../library/config.php' );
Try using getcwd() function.
That is
include(getcwd()."path to config.php");

php include_once not working

What would be the reasons of a non working include_once?
Here's my folder hierarchy:
/Php/Controls/GridView/GridView.php
/Php/Controls/Form/Form.php
In "Form.php":
include_once '../GridView/GridView.php';
I'm getting this error:
Warning: include_once(../GridView/GridView.php) [function.include-once]: failed to open stream: No such file or directory in ...Form.php on line 4
Warning: include_once() [function.include]: Failed opening '../GridView/GridView.php' for inclusion (include_path='.;C:\php\pear') in ...Form.php on line 4
Please tell me if you want more information.
In Form.php use
include_once dirname(__FILE__) . '/../GridView/GridView.php';
This creates an absolute path, but relative to the file, where its called from.
It can't find the file.
You should use a full path, like /Php/Controls/GridView/GridView.php instead of a relative one.
Try this:
include_once './php/Controls/GridView/GridView.php';
Hope I'm not too late on this one but I thought this might be what you're looking for:
include_once realpath(dirname(__FILE__)."/../GridView/GridView.php");
Using realpath() allows you to include files even from outside your server document root directory.

Warning and Fatal error calling require_once()

I want to fetch div element from other website .
on which iam having my profile, i have tried using this code.
require_once('../simple_html_dom.php');
$html=file_get_html('http://www.example.com');
$ret=$html->find("div[id=frame-gallery]");
$ret=array_shift($ret);
echo($ret);
but this code is giving errors
Warning:
require_once(../simple_html_dom.php)
[function.require-once]: failed to
open stream: No such file or directory
in
E:\wamp\www\in.com\components\com_content\view.php
on line 22
Fatal error: require_once()
[function.require]: Failed opening
required '../simple_html_dom.php'
(include_path='.;./includes;./pear')
in
E:\wamp\www\in.com\components\com_content\view.php
on line 22
iam stuck with this plz help me with the code snippets for fetching the specific div element from a website
The file simple_html_dom.php is not where you're telling PHP to look for it.
require_once('../simple_html_dom.php');
To be safe, try using the full path instead of a relative path.
require_once('E:\wamp\www\in.com\components\simple_html_dom.php');
BTW, if the full path above is incorrect, then that is your problem. This is the path that PHP is trying.
To clarify: I'm only suggesting the OP switch to absolute paths to identify and confirm the source of the issue. Going to production with absolute paths is rarely a good idea.
require and include paths can be tricky in PHP. Try to use full paths when you can. You'll find $_SERVER['DOCUMENT_ROOT'] usefull for that.
Your inlude_path should contain ".", which means current directory.
But if you having troubles with including file by relative name, then just try to use absolute names, like require_once('E:\wamp\www\in.com\components\simple_html_dom.php');
But better it should be:
require_once 'E:/wamp/www/in.com/components/simple_html_dom.php';

Categories