I'm trying to require_once a file in a document; here's my current syntax:
$path = $_SERVER['DOCUMENT_ROOT'];
require_once("includes/save-email.php");
The problem is that, when I reload my page in my browser, every element disappears and I get the following two messages:
Warning: require_once(/includes/connect.php) [function.require-once]: failed to open stream: No such file or directory in /homepages/3/[my db name]/htdocs/includes/save-email.php on line 2
Fatal error: require_once() [function.require]: Failed opening required '/includes/connect.php' (include_path='.:/usr/lib/php5') in /homepages/3/[my db name]/htdocs/includes/save-email.php on line 2
I've tried every variation of the link I can think of, including ../link, ./link, /link, and link.
Strangely enough, when I include an element of the layout using the same overall syntax (replacing require_once with include), that element loads without any errors, even though it's in the same directory.
I'm not sure that it matters, but my server is run by 1&1.
require_once(/includes/connect.php) will look for the file in the root of your server not in the current folder
repalace
require_once(/includes/connect.php)
by
require_once(includes/connect.php)
in save-email.php on line 2
setting $path won't do anything. you will need to have the includes folder in the same folder as this php document.
Related
I am trying to make a login system for my app, and needed to use php for it. However I'm really new to php so I got errors. First of all, I am using a free web hosting for now, so it might be the issue here. That being said, here is the error part of my php:
<?php
require_once 'include/DB_Functions.php';
?>
And it gives me this error:
Warning: require_once(include/DB_Functions.php): failed to open stream: No such file or directory in /srv/disk3/1965965/www/yigittest.atwebpages.com/login.php on line 2
Fatal error: require_once(): Failed opening required 'include/DB_Functions.php' (include_path='.:/usr/local/php-5.4.45/share/pear') in /srv/disk3/1965965/www/yigittest.atwebpages.com/login.php on line 2
However, my include folder contains all the required php files. So what might be the issue here?
Try this demo code or plz share your folder structure
require_once(__DIR__.'/../include/DB_Functions.php');
I have class called client, and there i have function, in which i'm trying to include/execute php file, but when i'm doing it all path's in that file which i'm trying to include goes wrong.
class function:
public static function SendSSHCommand($ssh_cmd) {
include('../Core/core_class.php');
$ssh = new samp_panel();
$ssh->SendCommand($ssh_cmd);
}
I would like get a solution, how to include file, that all directory path's in that file wouldn't go wrong.
I get many errors like that:
Warning: include(Net/SSH2.php): failed to open stream: No such file or directory in /home/vlkg/domains/vlkg.lt/public_html/naujas/Core/core_class.php on line 30
Warning: include(Net/SSH2.php): failed to open stream: No such file or directory in /home/vlkg/domains/vlkg.lt/public_html/naujas/Core/core_class.php on line 30
Warning: include(): Failed opening 'Net/SSH2.php' for inclusion (include_path='.:/usr/share/pear:Core/NetModule') in /home/vlkg/domains/vlkg.lt/public_html/naujas/Core/core_class.php on line 30
Fatal error: Class 'Net_SSH2' not found in /home/vlkg/domains/vlkg.lt/public_html/naujas/Core/core_class.php on line 366
I always change my include directory when I run a script. For me it just makes it easier if I set a point of reference for all my included files.
http://php.net/manual/en/function.set-include-path.php
Put something like this at the top of your file
set_include_path('/usr/www/2/main');
include('include1.php');
include('subdir_of_include_path/include2.php');
There are several options but this is the one I find useful with my projects. This way I force and know what my include path is.
I am new to moodle. I am trying to query the moodle database using my own PHP scripts. I am using the data manipulation API but i can't seem to fetch anything. What are the steps i should take to accomplish this. I have seen a number of guidelines here and there that I should include the config.php file in moodle so as to access the $DB global variable and hence access the functions of the DML API. The following is my code:
<?php
require '../config.php';
global $DB;
$user= $DB->get_record_sql('SELECT * FROM {mdl_user} WHERE id=?', array(4));
echo mysql_num_rows($user);
?>
I get the following error when I try to run it on TextMate editor:
PHP Warning: Â require(../config.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/moodle24/sbs_android_app/database_manipulation.php on line 2
PHP Fatal error: Â require(): Failed opening required '../config.php' (include_path='.:') in /Applications/MAMP/htdocs/moodle24/sbs_android_app/database_manipulation.php on line 2
I will appreciate the help...Thanks.
This error:
PHP Warning: require(../config.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/moodle24/sbs_android_app/database_manipulation.php on line 2
means that the script can't find a file called config.php. ../config.php means the script is going to try and open a file in the script's parent directory called config.php. Be sure your script is actually in that location. If it is not, I recommend changing ../config.php to ./config.php and moving your script into the same directory as config.php.
Because your script can't find config.php, it can't connect to the database (config.php should store the credentials, URL, ect.)
I think you are giving wrong path. please be sure that the path you are giving is correct like
require_once('path_from_rootdir to config.php');
note: path_from_rootdir to config.php is the path to config.php and each directory between the path separated by '/'.
There are two issues with this (as wriiten in the question) four lines code of Moodle-
require '../config.php';
Here code is getting error- "PHP Warning: require(../config.php): failed to open stream" because config.php is being looked into the parent directory & file is not there. Please check the path & put the correct path of config.php.
$user= $DB->get_record_sql('SELECT * FROM {mdl_user} WHERE id=?', array(4));
While working with Moodle DML API, table prefix(by default mdl_) must not be added before the table name within {}. Thus, there must be only {user} in place of {mdl_user}.
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.
I have encountered a problem that I have not come accross yet when setting up a log in page using php.
The page has a error message that relates to line 1 ( require_once('../Connections/Login.php)
that states
[function.require-once]: failed to open stream: No such file or directory
Fatal Error: require_once() [function.require]: failed opening required ... (include_path='.:/usr/share/pear-php5')
I know it is probably really simple and stupid, but I'm really struggling to self-troubleshoot and would really value some help please?
This is where I have been so confused. I also thought the same, that it just couldn't find the file; however the structure is just as you have said:
htdocs/comparison.php (the log in page)
htdocs/Connections/connComparisonLogin.php
Sorry this is going to confuse you, I simplified the actual script in my original question and here is the actual error message:
Warning: require_once(../Connections/connComparisonLogin.php) [function.require-once]: failed to open stream: No such file or directory in /home/fhlinux135/s/suzukigenuine.com/user/htdocs/comparison.php on line 1
Fatal error: require_once() [function.require]: Failed opening required '../Connections/connComparisonLogin.php' (include_path='.:/usr/share/pear-php5') in /home/fhlinux135/s/suzukigenuine.com/user/htdocs/comparison.php on line 1
Have I done it all wrong?
I think your require statement should be:
require_once 'Connections/connComparisonLogin.php';
Where is your "Connections/Login.php" relative to the currrent php file.
php will look for the file relative to the current file, or, in one of the directories specified in the "include_path" php.ini setting.
The error just means php can't find the Login.php file. Assuming the page you are calling is index.php you should have a director structure like
-Dir1
|-index.php
-Connections
|-Login.php
Why are you going up a directory in your require statement? Remove the "../" from the beginning of your require_once path.