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 ?
-
To test that there isn't a problem with your include, can you try putting the include files in the same folder as the index.php and change the includes to 'steamauth.php' and 'userinfo.php'? Let me know if that works?MikeyBunny– MikeyBunny2017-10-27 20:45:08 +00:00Commented Oct 27, 2017 at 20:45
-
If that works, put the files back in steamauth and change your includes to "{$_SERVER[DOCUMENT_ROOT]}/steamauth/steamauth.php" and "{$_SERVER[DOCUMENT_ROOT]}/steamauth/userinfo.php". NOTE: You must change the single quotes to double quotes to test this. Let me know if that works.MikeyBunny– MikeyBunny2017-10-27 20:49:23 +00:00Commented Oct 27, 2017 at 20:49
-
Next, create a test file "index.php" in the steamauth folder and simply put "<?php print "hello"; ?> in it. Then try and load [your domain]/steamauth/index.php in your browser. Does the page load?MikeyBunny– MikeyBunny2017-10-27 20:52:20 +00:00Commented Oct 27, 2017 at 20:52
-
This also seems to be a duplicate of your question 2 days ago (with a few minor changes). Next time you should add more details to your existing question rather than creating the question again.MikeyBunny– MikeyBunny2017-10-27 20:55:23 +00:00Commented Oct 27, 2017 at 20:55
-
the thing is i have 1 more file that i didnt mention called navbar.php and i can include it no problem. i can even access the index.php in steamauth folder that you wrote about . But i can not include those 2 files : userinfo.php and steamauth.php although they have the same permissions as the other files. Any ideas ?shimonchick– shimonchick2017-10-27 21:03:07 +00:00Commented Oct 27, 2017 at 21:03
1 Answer
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.