Php 陷入一个奇怪的路径错误
我有路径错误: 警告:require_once(test/assets/includes/memberfunc.php):无法打开流:第4行的C:\xampp\htdocs\test\assets\includes\logininc.php中没有此类文件或目录 致命错误:require_once():在第4行的C:\xampp\htdocs\test\assets\includes\logininc.php中打开所需的“test/assets/includes/memberfunc.php”(include_path=';C:\xampp\php\PEAR')失败 然而我的道路是正确的。基本目录是测试。测试是我所有页面的位置。上面是assets/includes/logininc.php和assets/configs/db_config.php。一切都应该是正确的。请告知 这是我非常简单的表单,它位于名为login.php的测试中Php 陷入一个奇怪的路径错误,php,Php,我有路径错误: 警告:require_once(test/assets/includes/memberfunc.php):无法打开流:第4行的C:\xampp\htdocs\test\assets\includes\logininc.php中没有此类文件或目录 致命错误:require_once():在第4行的C:\xampp\htdocs\test\assets\includes\logininc.php中打开所需的“test/assets/includes/memberfunc.php”(i
<form id="login-form" method="post" action="assets/includes/logininc.php"> <fieldset>
<legend>Login </legend>
<p>Please enter your username and password to access the administrator's panel</p>
<label for="username"> <input type="text" name="username" id="username" />Username: </label> <label for="password"> <input type="password" name="password" id="password" />Password: </label> <label for="submit"> <input type="submit" name="submit" id="submit" value="Login" /> </label> </fieldset> </form>
登录
请输入您的用户名和密码以访问管理员面板
用户名:密码:
这反过来又引导我到下面的文件。Logininc.php。它位于assets/includes/logininc.php中
<?php
require_once("/test/assets/includes/memberfunc.php"); //LINE 4
require_once("/test/assets/config/db_config.php");
session_start();
if($_SESSION['logged_in'] ==true) {
redirect('/test/index.php');
echo "success";
}
else{
if ( (!isset($_POST['username'])) || (!isset($_POST['password'])) or
(!ctype_alnum($_POST['username'])))
redirect("/test/login.php");
}
$mysqli = @new mysqli(HOST, NAME, PW, DB);
//check connection
if(mysqli_connect_errorno())
{
printf("Unable to connect to DB! : %s",
mysqli_connect_error());
exit();
}
//Escape unsafe chars
$username = $mysqli->real_escape_string($_POST['username']);
$username = $mysqli->real_escape_string($_POST['password']);
//Time to make a SQL Q for execution
$sql = "SELECT * FROM users WHERE username= '".$username . "'AND password = '" . md5($password) . "'";
$result = $mysqli->query($sql);
// If one row is returned, USER AND PW is valid!
if (is_object($result) && $result->num_rows == 1) {
//set session variable for login true
$_SESSION['logged_in'] = true;
redirect('../../index.php');
}
else{ //if number of rows is not one redirect back to login
redirect('../../login.php');
}
?>
请告知。如何使用
dirname(\uuuu文件)
:
“memberfunc.php”位于同一目录中,因此不需要路径。出于懒惰的考虑,我会将“db_config.php”的副本放在该目录中,这样您的语句就会如下所示:
require_once("memberfunc.php"); //LINE 4
require_once("db_config.php");
您需要的是当前的工作目录。这是通过两种不同的方式实现的: 相对路径:
require_once('./assets/includes/memberfunc.php');
绝对路径:
require_once(getcwd() . '/assets/includes/memberfunc.php');
这里的主要区别在于HTML模板基于传递给浏览器的URL构建其相对路径。PHP根据执行文件的磁盘目录构建其相对路径。Try
require\u once(“memberfunc.PHP”)代码>执行打印getcwd()
就在assets/includes/logininc.php
文件中的php开始标记之后,只是为了确定路径,因为几乎肯定是这样。@koala\u dev尝试过,但是我在db\u config中得到了完全相同的错误。我也试过你的建议,但不清楚。Daniel Figueroa尝试了你的建议,但似乎我的道路是对的?echo=C:\xampp\htdocs\test\assets\includes@JohnSmith那么db_config.php在另一个文件夹中,所以您需要针对该文件夹进行调整<代码>require_once(“../config/db_config.php”)
@koala_dev表示感谢,但我确信我已经尝试过了,所以我又尝试了一次,以防万一我失败了,但我回到了这个错误:警告:require_once(../config/db_config.php):无法打开流:在第7行的C:\xampp\htdocs\test\assets\includes\logininc.php中没有这样的文件或目录致命错误:require_once():在第7行的C:\xampp\htdocs\test\assets\includes\logininc.php中打开必需的“../config/db_config.php”(include_path=”;C:\xampp\php\PEAR)失败。好的,我已经尝试过了。但这是对的?我不明白。请参阅警告:require_once(C:\xampp\htdocs\test\assets\includes/test/assets/includes/memberfunc.php):无法打开流:第5行的C:\xampp\htdocs\test\assets\includes\logininc.php中没有此类文件或目录
require_once(getcwd() . '/assets/includes/memberfunc.php');