php 警告:未知:无法打开流:第 0 行的未知中没有此类文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18674298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
提问by 001221
Hi I am trying to make a members only website, I've trying to create a script with sessions etc however when I click my login button I get the following error:
嗨,我正在尝试创建一个仅限会员的网站,我尝试使用会话等创建脚本,但是当我单击登录按钮时,出现以下错误:
Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
Fatal error: Unknown: Failed opening required 'prepend.php' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in Unknown on line 0
Fatal error: Unknown: Failed opening required 'prepend.php' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in Unknown on line 0
I'm not 100% sure what this all means, so I'll post my script and would appreciate if somebody could tell me in depth where I'm going wrong so I can grasp and learn for the future what I'm doing wrong.
我不是 100% 确定这一切意味着什么,所以我会发布我的脚本,如果有人能深入告诉我我哪里出错了,我将不胜感激,这样我就可以掌握和了解我做错了什么.
Thanks in advance for any input and help.
在此先感谢您的任何意见和帮助。
index.php
索引.php
<div id="maincontentWrapper">
<div id="maincontent">
<div id="contentWrapper"></div><!--End loginWrapper -->
<article>
<p>Welcome to iManage, please login in below.</p>
</article>
<div id="loginform">
<div id="loginWrapper">
<form id="loginForm" method="POST" action="classes/class.Login.php">
<h1><span class="log-in">Log in</span> or <span class="sign-up"><a href="register">sign up</a></span></h1>
<div id="errorDiv"><?php
if (isset($_SESSION['error']) & isset($_SESSION['formAttempt'])) {
unset($_SESSION['formAttempt']);
print "Errors encountered<br/>\n";
foreach ($_SESSION['error'] as $error) {
print $error . "<br />\n";
} //end foreach
} //end if
?></div>
<p class="float">
<label for="login"><i class="icon-user"></i>Username</label>
<input type="text" id="email" name="email" placeholder="E-mail">
<span class="errorFeedback errorSpan" id="emailError">E-mail is required</span>
</p>
<p class="float">
<label for="password"><i class="icon-lock"></i>Password</label>
<input type="password" id="password" name="password" placeholder="Password" class="showpassword">
<span class="errorFeedback errorSpan" id="passwordError">Password is required</span>
</p>
<p class="clearfix">
<input type="submit" name="submit" value="Log in"></form>
</p>
</div>
</div>
</div>
</div>
</div>
classes/class.Login.php
类/class.Login.php
<?php
include("../connect/class.Connect.php");
class Login extends Database {
public $id;
public $email;
public $username;
public function __construct() {
if (session_id() == "") {
session_start();
}
if (isset($_SESSION['isLoggedIn']) && $_SESSION['isLoggedIn'] == true) {
$this->_initUser();
}
} // end construct
public function authenticate($user, $pass) {
$safeUser = $this->mysqli->real_escape_string($pass);
$query = "SELECT * from users WHERE email = '{$safeUser}'";
if (!$result = $this->mysqli->query($query)) {
error_log("Cannot retrieve account for {$user}");
return false;
}
// will be only one row, so no while() loop needed
$row = $result->fetch_assoc();
$dbPassword = $row['password'];
if (crypt($incomingPassword,$dbPassword) != $dbPassword) {
error_log("Passwords for {$user} don't match");
return false;
}
$this->id = $row['id'];
$this->username = $row['username'];
$this->email = $row['email'];
$this->isLoggedIn = true;
$this->_setSession();
return true;
} // end function autheticate
private function _setSession() {
if (session_id() == '') {
session_start();
}
$_SESSION['id'] = $this->id;
$_SESSION['email'] = $this->email;
$_SESSION['username'] = $this->username;
$_SESSION['isLoggedIn'] = $this->isLoggedIn;
} // end function setSession
private function _initUser() {
if(session_id() == '') {
sessions_start();
}
$_SESSION['id'] = $this->id;
$_SESSION['email'] = $this->email;
$_SESSION['username'] = $this->username;
$_SESSION['isLoggedIn'] = $this->isLoggedIn;
}// end function initUser
function validatelogin () {
$_SESSION['formAttempt'] = true;
if (isset($_SESSION['error'])) {
unset($_SESSION['error']);
}
$_SESSION['error'] = array();
$required = array("email","password");
//Check required fields
foreach ($required as $requiredField) {
if (!isset($_POST[$requiredField]) || $_POST[$requiredField] == "") {
$_SESSION['error'][] = $requiredField . " is required.";
}
}
if (!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) {
$_SESSION['error'][] = "Invalid e-mail address";
}
if (count($_SESSION['error']) > 0) {
die(header("Location: login.php"));
} else {
$user = new User;
if ($user->authenciate($_POST['email'], $_POST['password'])) {
unset($_SESSION['formAttempt']);
die(header("Location: authenticated.php"));
}else {
$_SESSION['error'][] = "There was a problem with your username or password.";
die(header("Location: login.php"));
}
}
}
}
$run = new Login();
$run->authenticate($user, $pass);
$run->validatelogin();
?>
prepend.php
前置.php
<?php
if (!isset($_SESSION) ) {
session_start();
}
?>
.htaccess
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ .php
php_value auto_prepend_file "prepend.php"
采纳答案by Alex
Set absolute path to prepend.php in .htaccess
在 .htaccess 中设置 prepend.php 的绝对路径
回答by TAHIR kamal
My antivirus software likes to put the router.php in quarantine (effectively removing it from that directory). Check if yours did the same and if so restore it and create an exception for that file. Additionally you should configure your antivirus to notify you if it puts something in quarantine, so you can intervene in time.
我的防病毒软件喜欢将 router.php 置于隔离区(有效地将其从该目录中删除)。检查你的是否做了同样的事情,如果是,则恢复它并为该文件创建一个例外。此外,您应该配置您的防病毒软件,以便在它隔离某些内容时通知您,以便您及时进行干预。
回答by Assad Yaqoob
This error come due to missing of server.php .Same happen with me. You check server.php file in your project directory.
这个错误是由于缺少 server.php 。我也发生了同样的情况。您检查项目目录中的 server.php 文件。