I want to require_once()
dbconnect.php
in register.php
. How do I do that? I tried re开发者_如何学编程quire_once('../dbconnect.php')
but that does not work (though it does work at the register
level.
require_once("../../dbconnect.php");
require_once dirname(__FILE__) . '/../../dbconnect.php';
Or if you are using PHP 5.3, replace dirname(__FILE__)
with __DIR__
.
If you wanted to be real anal, you could replace /
with the constant DIRECTORY_SEPARATOR
. :P
Is dbconnect.php inside public_html? if so you will need require_once('../../dbconnect.php')
Each ../ represents one directory up. At the moment it's looking in register for dbconnect.php
your code is true, from register folder, you will need to use require_once(../dbconnect.php)
. well, now we see require_once()
, "once" is mean it have to included only one time, maybe just check your code. is require_once(../dbconnect.php)
has been located at this script or other script that included? if you type require_once(../dbconnect.php)
more than one, this will error.
When u do
require_once('../dbconnect.php')
.. means the parent directory, so it goes one level up there. Still its there in the register folder. So, to go to its parent directory, you will have to specify one more .. where the file dbconnect.php exists. So you can also use it as
require_once __DIR__. '/../dbconnect.php';
精彩评论