Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php/cookies创建登录系统_Php_Session_Cookies - Fatal编程技术网

使用php/cookies创建登录系统

使用php/cookies创建登录系统,php,session,cookies,Php,Session,Cookies,如果有人不介意帮我的话,我真的很挣扎。我绝对不是php高手,这是肯定的 我正在尝试使用php/sessions/Cookie等创建一个登录系统,到目前为止,我所得到的似乎只是每次尝试登录时出现的一个错误(这意味着登录后基本上会用一个注销按钮向“用户”打招呼。我将尝试附加/减少我能做的 提前谢谢 php(带有登录按钮的主登录页面) session-login.php <div id="login"> <?php error_reporting(E_ALL|E_STRICT)

如果有人不介意帮我的话,我真的很挣扎。我绝对不是php高手,这是肯定的

我正在尝试使用php/sessions/Cookie等创建一个登录系统,到目前为止,我所得到的似乎只是每次尝试登录时出现的一个错误(这意味着登录后基本上会用一个注销按钮向“用户”打招呼。我将尝试附加/减少我能做的

提前谢谢

php(带有登录按钮的主登录页面)


session-login.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>


将session_start();放在
标记之前。确保前面没有其他输出。

谢谢!也非常简单!^这个指向最低学习php用户的^duplicate^链接完全是胡说八道。
<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>
<!doctype html><?php
////////////////////// START SESSION HERE ///////////////////////////
session_set_cookie_params(0, '/~b4019635', 'homepages.shu.ac.uk', 1, 1);
session_start();
?></html>
<?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']);
?>