有人可以帮我解释一下为什么我会在下面的代码中出现这个错误,请:
<html>
<head>
</head>
<body>
<?php
if (!(isset($_COOKIE["loggedin"]))){
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST" name="name_form">
Username <input type="text" name="username">
<br/>
Password <input type="text" name="password">
<br/>
Remember Me <input type ="checkbox" name="remember_me" value="1">
<br/>
<input type="submit" name="submit" value="Log in">
</form>
}
</body>
</html>
<?php
if(preg_match("/<|>/", $_POST["username"])){
echo "do not log in";
}
else if(preg_match("/<|>/", $_POST["password"])){
echo "do not log in";
}
else{
//Open/create passwords.txt
$passwordsFile = fopen("passwords.txt", "a");
//write users username and password to passwords.txt
$text_written = fwrite($passwordsFile, $_POST["username"] . "," . $_POST["password"] . "\r\n");
fclose($passwordsFile);
setcookie("loggedin", $_POST['username']);
setcookie("loggedintime", time());
}
?>
提前感谢您的帮助!我在这里看过类似的帖子,但无论如何我都无法解决这个问题......
答案 0 :(得分:2)
在结束PHP标记?>
之前,您似乎有一个额外的大括号,并且您忘记包装IF语句的前一个大括号}
:{{1}使用PHP结束和结束标记,正确的代码:
if (!(isset($_COOKIE["loggedin"]))){
答案 1 :(得分:1)
在php块中完成if括号..
<html>
<head>
</head>
<body>
<?php
if (!(isset($_COOKIE["loggedin"]))){
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST" name="name_form">
Username <input type="text" name="username">
<br/>
Password <input type="text" name="password">
<br/>
Remember Me <input type ="checkbox" name="remember_me" value="1">
<br/>
<input type="submit" name="submit" value="Log in">
</form>
<?php } ?>
</body>
答案 2 :(得分:1)
我在您的代码中进行了一些更改,第一个if条件的右括号在php标记(<html>
<body>
<p>
Lorem ipsum dolor sit amet enim. <span class="tooltip" data-text="Tooltip1"> Etiam ullamcorper.</span>Suspendisse a pellentesque dui, non felis. <span class="tooltip" data-text="Tooltip 2">Maecenas malesuada elit lectus</span> felis, malesuada ultricies. Curabitur et ligula.<span class="tooltip" data-text="Tooltip 3">Ut molestie a, ultricies porta urna.</span> Vestibulum
</p>
</body>
</html>
<script>
document.addEventListener("DOMContentLoaded", function() {
var tooltips = document.querySelectorAll(".tooltip");
var tooltipsValue = [];
console.log(tooltips);
for (var i = 0; i < tooltips.length; i++) {
var dataTags = tooltips[i].dataset.text;
tooltipsValue.push(dataTags);
//console.log(i);
//console.log(tooltipsValue);
//console.log(dataTags);
//tooltips[i].dataset.text;
//var dataTag = tooltips[i].dataset.text;
//console.log(tooltips[i].dataset.text);
tooltips[i].addEventListener('mouseover', function() {
//console.log("text while mouseover");
//console.log(tooltipsValue[i]);
});
tooltips[i].addEventListener('mouseout', function() {
//console.log("text after mouseout");
});
}
});
</script>
)中没有。尝试给password.txt文件读写权限
<?php ... ?>
答案 3 :(得分:1)
尝试
if (!isset($_COOKIE["loggedin"])){
而不是
if (!(isset($_COOKIE["loggedin"]))){