0

我有路径错误:

警告:require_once(test/assets/includes/memberfunc.php):无法打开流:第 4 行的 C:\xampp\htdocs\test\assets\includes\logininc.php 中没有这样的文件或目录

致命错误:require_once():在 C:\xampp\htdocs\test\assets\includes 中打开所需的 'test/assets/includes/memberfunc.php' (include_path='.;C:\xampp\php\PEAR') 失败\logininc.php 在第 4 行

然而我的道路是正确的。基本目录是测试。测试是我所有页面所在的位置。上面是 assets/includes/logininc.php 和 assets/configs/db_config.php。一切都应该是正确的。请指教

这是我非常简单的表单,它位于名为 login.php 的测试中。

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

这反过来又将我引导到下面的文件。登录inc.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');
}

    
    ?>

.

请指教。

4

3 回答 3

1

'memberfunc.php' 位于同一目录中,因此您不需要路径。出于懒惰,我也会在该目录中放置一个“db_config.php”的副本,这样您的语句就会如下所示:

require_once("memberfunc.php");  //LINE 4
require_once("db_config.php"); 
于 2013-07-23T00:15:42.477 回答
0

你想要的是当前的工作目录。这是通过两种不同的方式实现的:

相对路径:

require_once('./assets/includes/memberfunc.php');

绝对路径:

require_once(getcwd() . '/assets/includes/memberfunc.php');

这里的主要区别在于 HTML 模板基于传递给浏览器的 URL 构建其相对路径。PHP 根据文件执行的磁盘目录构建其相对路径。

于 2013-07-23T00:18:31.793 回答
0

如何使用dirname(__FILE__)

require_once(dirname(__FILE__)."/test/assets/includes/memberfunc.php");
require_once(dirname(__FILE__)."/test/assets/config/db_config.php"); 
于 2013-07-22T22:42:09.353 回答