php包含错误找不到路径 [英] php include error not findind the path

查看:34
本文介绍了php包含错误找不到路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个小代码,它实际上是一个登录脚本,它检查注册是否打开,并在登录按钮后显示:

I have this little code, which in fact is a login script which check if the register is on, and show it after the login button:

   <?php
include("../inc/db.php"); 
if(isset($_POST['user']) && isset($_POST['pass']))
{
    $password = $_POST['pass'];
    $username = $_POST['user'];

    $sql = "SELECT * FROM `users` WHERE `user` = '".$username."' AND `password` = '".$password."'";
    $rez = $pdo->query($sql);   
    if($rez->fetchColumn()  > 0)
    {
        ...

    }
    else {echo '<p align="center">...</p>';}
    }
    else { echo '<p align="center">...</p>'; }
    }
    ?>
    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
    <form name="form1" method="post" action="login">
    <td>
    <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
    <tr>
    <td colspan="3"><strong>Member Login </strong></td>
    </tr>
    <tr>
    <td width="78">Username</td>
    <td width="6">:</td>
    <td width="294"><input name="user" type="text" id="user"></td>
    </tr>
    <tr>
    <td>Password</td>
    <td>:</td>
    <td><input name="pass" type="password" id="pass"></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="Login"></td>
    </tr>
    <?php $sql = "SELECT setare FROM setari WHERE nume_setare = 'OPEN_REG'";
    $openreg = $pdo->query($sql)->fetch();
    if($openreg['setare'] == 1)
    {
     ?>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><a href="register">Inregistrare</a></td>
    </tr><?php } ?>
    </table>
    </td>
    </form>
    </tr>
    </table>

我的问题是这一行:

include("../inc/db.php");警告:include(E:/wamp/www//inc/db.php): 无法打开流:第 3 行的 E:\wamp\www\proiect1-test\scripts\login.php 中没有这样的文件或目录警告:include():在 E:\wamp\www\proiect1-test\scripts\login 中打开 '../inc/db.php' 进行包含失败 (include_path='.;C:\php\pear').第 3 行的 php

include("../inc/db.php"); Warning: include(E:/wamp/www//inc/db.php): failed to open stream: No such file or directory in E:\wamp\www\proiect1-test\scripts\login.php on line 3 Warning: include(): Failed opening '../inc/db.php' for inclusion (include_path='.;C:\php\pear') in E:\wamp\www\proiect1-test\scripts\login.php on line 3

我不知道我错在哪里.路径是正确的,如果我点击登录按钮,它就可以工作.如果我用不正确的用户名和密码组合点击登录按钮,警告就会消失.但是,当我第一次打开它时,它不包括在内.此登录文件包含在站点的索引中.

and i can't figure it out where i'm wrong. The path is correct, and if i hit the login button, it works.If i hit login button with an inccorect combination of username and password, the warning disappear. However, it doesn't include that when i open it for the first time. This login file is included in the index of the site.

推荐答案

该文件的路径显然不正确.当您使用文件的相对路径然后开始将文件放在不同的目录中时,通常会发生这种情况.您应该使用文件的完整系统路径来避免此问题:

Your path to that file is obviously incorrect. This commonly happens when you use a relative path to a file and then start placing files in different directories. You should use the full system path to the file to avoid this issue:

include("/path/from/root/to/inc/db.php"); 

通常要做的事情是定义一个变量或常量,用于定义 Web 文件的根路径.这样,如果它发生变化(即您更换主机),您只需在一个地方更改它.

A common thing to do is define a variable or constant that defines the root path to your web files. That way if it ever changes (i.e. you change hosts) you only need to change it in one place.

在您的配置文件中:

define('ROOT_PATH', '/path/from/root/to/');

在您的 PHP 文件中;

In your PHP files;

include(ROOT_PATH . "inc/db.php"); 

这篇关于php包含错误找不到路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆