PHP的包括错误没有findind路径 [英] php include error not findind the path

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

问题描述

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

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的包括错误没有findind路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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