I'm working on a php web application under windows. I have many script files placed in their respective folders and all the files needs a file named 'connexion.php' that is situated in the root project.
The structure of the project is as follow:
Projet_beta :
-client (folder):
*addClient.php
*modifyClient.php
*deleteClient.php
- connexion.php
So, when i use include ('../connexion.php') inside the 'addClient.php' it displays this error message :
Warning: include(connexion.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\project_beta\client\addClient.php on line 3.
How can i fix this problem ?
Thank's every one.
Try this include ('/../connexion.php')
The extra slash should solve your issue.
Check in your httpd.conf file :
left click on wamp
php menu
open the httpd.conf file
Find the line starting with DocumentRoot
Change the line to DocumentRoot "c:/wamp/www/" and save the file
Restart wamp services
Then use :
include($_SERVER['DOCUMENT_ROOT'] . '/project_beta/connexion.php');
Should use
dirname(__FILE__)."../connexion.php"
instead.
In this case, "../" search files from the path you executing the file, not the real path of the file.
You can use dirname func :
include(dirname(__FILE__)."/connexion.php"));
Windows versions of PHP prior to PHP 4.3.0 do not support access of remote files via this function, even if allow_url_fopen is enabled.
Related
Im runninng lamp stack locally on my ubuntu 16.04 OS and Im getting problems when including files. My code in index.php:
<?php include('steamauth/steamauth.php'); ?>
<?php include('steamauth/userinfo.php');?>
my structure is:
index.php
steamauth
steamauth.php
userinfo.php
Im getting the following error:
include(steamauth/userinfo.php): failed to open stream: No such file or directory in /var/www/html/index.php
include(): Failed opening 'steamauth/userinfo.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/index.php
I tried using the full path , adding webroot before the path , changing include_path in php.ini , but nothing seemed to work . what do i do ?
Check folder pemission
Check that the Apache user has access to the include folder.
Check file permissions
Check that the permissions on the files that you are including can be read and executed by the Apache user.
Check PHP settings
It could be caused by one of the following PHP settings:
open_basedir:
If this is set PHP won't be able to access any file outside of the specified directory (not even through a symbolic link).
safe mode:
If this is turned on restrictions might apply.
Make path absolute
Check that $_SERVER["DOCUMENT_ROOT"] is correctly set for your domain by using:
print $_SERVER["DOCUMENT_ROOT"]; // Add to top of you index.php file.
Then change your includes to:
$_SERVER["DOCUMENT_ROOT"] . '/sub_folder/file_to_include';
Check for typos and spelling mistakes
Carefully check that what you think you have called the folder and what you are using to include it are spelt the same.
BTW: You can just use the following in your index.php file:
<?php
include('steamauth/steamauth.php');
include('steamauth/userinfo.php');
You also don't need to add the closing ?> at the end of the file - it's actually good practice not to.
I am trying to include a php file in a page via
require_once(http://localhost/web/a.php)
I am getting an error
Warning: require_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0
I changed allow_url_include=1 in the php.ini and that worked but I don't think that everybody will let me change their php.ini file.
So, is there any way to accomplish this?
The warning is generated because you are using a full URL for the file that you are including. This is NOT the right way because this way you are going to get some HTML from the webserver. Use:
require_once('../web/a.php');
so that webserver could EXECUTE the script and deliver its output, instead of just serving up the source code (your current case which leads to the warning).
I had this same error while trying to include a PHP file in my Wordpress theme. I was able to get around it by referencing the file name using dirname(__FILE__). I couldn't use relative paths since my file was going to be included in different places throughout the theme, so something like require_once '../path-to/my-file' wouldn't work.
Replacing require_once get_template_directory_uri() . '/path-to/my-file' with require_once dirname( __FILE__ ) . '/path-to/my-file' did the trick.
try to use
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/web/a.php'); ?>
You have to put the path to the file. For example:
require_once('../web/a.php');
You cannot get the file to require it from internet (with http protocol) it's restricted. The files must be on the same server. With Possibility to see each others (rights)
Dir-1 -
> Folder-1 -> a.php
Dir-2 -
> Folder-2 -> b.php
To include a.php inside b.php => require_once('../../Dir-1/Folder-1/a.php');
To include b.php inside a.php => require_once('../../Dir-2/Folder-2/b.php');
WORDPRESS is having this error mostly:
SOLUTION:
Locate your PHP installed directory on Remote live hosting SERVER or "Local Server"
In case of Windows os
for example if you using xampp or wamp webserver. it will be in xammp directory
'c:\xammp\php'
Note: For Unix/Linux OS, locate your PHP directory in Webserver
Find & Edit PHP.INI file
Find 'allow_url_include'
replace it with value 'on'
allow_url_include=On
Save you php.ini & RESTART you web-server.
require_once('../web/a.php');
If this is not working for anyone, following is the good Idea to include file anywhere in the project.
require_once dirname(__FILE__)."/../../includes/enter.php";
This code will get the file from 2 directory outside of the current directory.
include and require functions require file path, but you are giving file URI instead. The parameter should not be the one that includes http/https.
Your code should be something like:
include ("folder/file.php");
For me the resolution with sending data on a PHP request:
$ch = curl_init('https://localhost/request.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_REQUEST));
echo curl_exec($ch);
curl_close($ch);
require_once(APPPATH.'web/a.php');
worked for me in codeigniter
check reference
echo file_get_contents('http://localhost/web/a.php'); //Best Example
Hi I am getting this error, when I run the index.php file which includes
require_once("system/config.php");
I am wondering what does this message mean, and how do I go about fixing such an issue. As this site worked fine when I ran it directly on my Mac.
require_once(): Failed opening required 'system/core.php' (include_path='.:/usr/share/php')
ALL THE BELOW ANSWERS ARE CORRECT!
However my issue was a CHMOD issue I had 644 instead of 744
It usually means you're trying to include the file with an incorrect path. What happens when you try the full path?
require_once(getcwd() . 'system/config.php');
The way your script is now, it's looking for the file with a directory structure like this:
file.php <- is calling the require_once()
- system <- the system directory
- config.php <- the config file
But this isn't the path where it's located.
The file system/core.php needs to be relatively to the file which is declaring the line require_once("system/core.php"); (that's system/config.php) or the direcory that contains system must be in your include_path. Search for core.php on your Mac. Check the configuration settings (include_path) on your Mac.
I am trying to include a php file in a page via
require_once(http://localhost/web/a.php)
I am getting an error
Warning: require_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0
I changed allow_url_include=1 in the php.ini and that worked but I don't think that everybody will let me change their php.ini file.
So, is there any way to accomplish this?
The warning is generated because you are using a full URL for the file that you are including. This is NOT the right way because this way you are going to get some HTML from the webserver. Use:
require_once('../web/a.php');
so that webserver could EXECUTE the script and deliver its output, instead of just serving up the source code (your current case which leads to the warning).
I had this same error while trying to include a PHP file in my Wordpress theme. I was able to get around it by referencing the file name using dirname(__FILE__). I couldn't use relative paths since my file was going to be included in different places throughout the theme, so something like require_once '../path-to/my-file' wouldn't work.
Replacing require_once get_template_directory_uri() . '/path-to/my-file' with require_once dirname( __FILE__ ) . '/path-to/my-file' did the trick.
try to use
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/web/a.php'); ?>
You have to put the path to the file. For example:
require_once('../web/a.php');
You cannot get the file to require it from internet (with http protocol) it's restricted. The files must be on the same server. With Possibility to see each others (rights)
Dir-1 -
> Folder-1 -> a.php
Dir-2 -
> Folder-2 -> b.php
To include a.php inside b.php => require_once('../../Dir-1/Folder-1/a.php');
To include b.php inside a.php => require_once('../../Dir-2/Folder-2/b.php');
WORDPRESS is having this error mostly:
SOLUTION:
Locate your PHP installed directory on Remote live hosting SERVER or "Local Server"
In case of Windows os
for example if you using xampp or wamp webserver. it will be in xammp directory
'c:\xammp\php'
Note: For Unix/Linux OS, locate your PHP directory in Webserver
Find & Edit PHP.INI file
Find 'allow_url_include'
replace it with value 'on'
allow_url_include=On
Save you php.ini & RESTART you web-server.
require_once('../web/a.php');
If this is not working for anyone, following is the good Idea to include file anywhere in the project.
require_once dirname(__FILE__)."/../../includes/enter.php";
This code will get the file from 2 directory outside of the current directory.
include and require functions require file path, but you are giving file URI instead. The parameter should not be the one that includes http/https.
Your code should be something like:
include ("folder/file.php");
For me the resolution with sending data on a PHP request:
$ch = curl_init('https://localhost/request.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_REQUEST));
echo curl_exec($ch);
curl_close($ch);
require_once(APPPATH.'web/a.php');
worked for me in codeigniter
check reference
echo file_get_contents('http://localhost/web/a.php'); //Best Example
I am an amateur web developer and I am trying to get my site live for the first time. The site is working and all of the files are uploaded but the site is not loading my PHP includes.
Here is the error message:
Warning: include(includes/header.php) [function.include]: failed to open stream: No such file or directory in /home4/myUsername/public_html/index.php on line 3
How can I get PHP to look in public_html/ rather than public_html/index.php?
EDIT: I have tried editing the include path. It doesn't seem to change where php is looking for the file. Additionally my includes work properly in localhost.
I'm going to assume this is your folder structure:
public_html/index.php
public_html/includes/header.php
Generally (not always), $_SERVER['DOCUMENT_ROOT'] will now reflect the path to the base public_html directory (this I'm assuming based on the context of your message). This means you can always point to the root this way. - no matter if you have /index.php or /my/deep/file/structure.php
Try this with your include statement on index.php
<?php
include($_SERVER['DOCUMENT_ROOT'] . '/includes/header.php');
You may need to change the include path in your php.ini file or use set_include_path() to change the include path.
Here is the manual entry for the function call if you'd like to read more about it.
Have you checked already the include file?
in given. include(folder_includes/file_header.php);