Jump to content

Warning Include


Glese

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/251959-warning-include/
Share on other sites

 

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';

Link to comment
https://forums.phpfreaks.com/topic/251959-warning-include/#findComment-1291819
Share on other sites

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. 

Link to comment
https://forums.phpfreaks.com/topic/251959-warning-include/#findComment-1291821
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/251959-warning-include/#findComment-1291828
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.