如果有人不介意帮助我,我真的很挣扎。我绝对不是这肯定显示的 php 大师!
我正在尝试使用 php/sessions/cookie 等制作登录系统,到目前为止,每当我尝试登录时,我似乎都会得到一个错误(它意味着登录然后基本上说你好"用户"以及注销按钮。我会尝试附加/减少我能做的。
提前感谢!
索引.php(带登录按钮的主登录页面)
<?php
include('includes/sessions.inc.php');
?>
<?php
/////////////////////////// conditional includes here
if(isset($_SESSION['login'])){
include('includes/session-logout.inc.php');
}else{
include('includes/session-login.inc.php');
}
?>
会话登录.php
<div id="login">
<?php
error_reporting(E_ALL|E_STRICT); ini_set('display_errors', true);
if($_SESSION['count'] > 0 && $_SESSION['count'] <= 3 ){
echo "<p class='"error'">Sorry incorrect</p>";
}
if($_SESSION['count'] > 3){
echo "<p class='"error'">Too many attempts</p>";
}else{
// don't forget to close this with } after the HTML form
?>
<form id="loginForm" name="loginForm" method="post" action="logic/checklogin.php">
<label for="username">Username</label>
<input name="username" type="text" id="username">
<label for="password">Password</label>
<input name="password" type="password" id="password">
<input type="submit" name="Submit" value="Login">
</form>
<?php
}
?>
</div>
会话.php
<!doctype html><?php
////////////////////// START SESSION HERE ///////////////////////////
session_set_cookie_params(0, '/~b4019635', 'homepages.shu.ac.uk', 1, 1);
session_start();
?></html>
检查登录.php
<?php
error_reporting(E_ALL|E_STRICT); ini_set('display_errors', true);
// check login and create SESSION and count attempts
include('../includes/sessions.inc.php');
//check login / password combination
if ($_POST['username'] == "admin" && $_POST['password'] == "letmein"){
$_SESSION['login'] = 1;
}else{
if(!isset($_SESSION['count'])){
// first fail
$_SESSION['count'] = 1;
}else{
// 2nd or more fail
$_SESSION['count']++;
}
}
// redirect browser
header("Location: ".$_SERVER['HTTP_REFERER']);
?>
我觉得 session_start(); 与它有关,因为在检查器中没有创建 cookie?
将
session_start()放在<!doctype html>
标记之前。确保它之前没有其他输出。