Glese Posted November 28, 2011 Share Posted November 28, 2011 Even though the path is right I am getting a warning: Warning: include(/php_projects/myproject/controller/registering/register_2.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\php_projects\myproject\controller\authentication\login_register.php on line 7 I am trying to include the file register_2.php into login_register.php, and the path is right I double checked it, I am trying to use an absolute path excluding the domain instead of a relative path. This is how I include the login_register.php file: <?php include ($register_2); ?> And this is the path.php file just to showcase: // The Login Register Page $register_2 = root . "controller/registering/register_2.php"; $login_2 = root . "controller/authentication/login_2.php"; And the define function: define('root', '/php_projects/myproject/'); With other paths this method does work, but it does not seem to work with paths which are a bit deeper in the structure. And I am wondering, why? Even using the domain, which means, putting the localhost in front of it does not work. Only a relative path will work. Quote Link to comment https://forums.phpfreaks.com/topic/251959-warning-include/ Share on other sites More sharing options...
freelance84 Posted November 28, 2011 Share Posted November 28, 2011 C:\xampp\htdocs\php_projects\myproject\controller\authentication\login_register.php If you want to go from the above to: C:\xampp\htdocs\php_projects\myproject\controller\registering\register_2.php Have you tried just using to see if it works? require_once '../registering/register_2.php'; Quote Link to comment https://forums.phpfreaks.com/topic/251959-warning-include/#findComment-1291819 Share on other sites More sharing options...
willfitch Posted November 28, 2011 Share Posted November 28, 2011 Looking at the warning, PHP is looking for your script in: C:/php_projects/myproject/controller/registering/register_2.php You need to update your include statement to reference the root directory of your project - not the disk. define('root', 'C:/xampp/htdocs/php_projects/myproject/'); Also, it's good convention to make your constants uppercase. Quote Link to comment https://forums.phpfreaks.com/topic/251959-warning-include/#findComment-1291821 Share on other sites More sharing options...
PFMaBiSmAd Posted November 28, 2011 Share Posted November 28, 2011 A leading slash / on a file system path refers to the root of the current hard disk. File system paths are not URLs and a leading slash / does not refer to the domain root like it does for a URL. See this post for how you can get the path to your document root folder - http://www.phpfreaks.com/forums/index.php?topic=348498.msg1644442#msg1644442 Quote Link to comment https://forums.phpfreaks.com/topic/251959-warning-include/#findComment-1291828 Share on other sites More sharing options...
Glese Posted November 28, 2011 Author Share Posted November 28, 2011 Using c:/ instead does not seem to work for me, I will look into this more. Quote Link to comment https://forums.phpfreaks.com/topic/251959-warning-include/#findComment-1291840 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.