Php 如何将现有的登录脚本集成到每个页面上的新登录表单中?

Php 如何将现有的登录脚本集成到每个页面上的新登录表单中?,php,forms,session,login,Php,Forms,Session,Login,几周前,我在我的网站上集成了一个开源的文件管理员,其中包括一个登录/会员系统。(可以找到文件管理员) 因为我正在学习web开发,所以我认为将这个登录系统集成到我的整个网站上是个好主意。 因此,我在标题中添加了必要的php代码以保持连接(包括在每个页面上),注销脚本也不是问题 但我的问题是登录表单。这是我制作的(在我的header.php文件中): 保持联系 登录成功正在重定向。。。 下面是administrator用于登录用户的原始完整login.php文件(我打算在我的文件准备好后将其删除

几周前,我在我的网站上集成了一个开源的文件管理员,其中包括一个登录/会员系统。(可以找到文件管理员)

因为我正在学习web开发,所以我认为将这个登录系统集成到我的整个网站上是个好主意。 因此,我在标题中添加了必要的php代码以保持连接(包括在每个页面上),注销脚本也不是问题

但我的问题是登录表单。这是我制作的(在我的header.php文件中):


保持联系
登录成功
正在重定向。。。
下面是administrator用于登录用户的原始完整login.php文件(我打算在我的文件准备好后将其删除):


使表单元素名称和表单操作与原始登录表单的名称和操作匹配。

使表单元素名称和表单操作与原始登录表单的名称和操作匹配。

只需更改表单字段的名称以与同事表单上的字段匹配即可。如需更改此项:
。对所有输入元素进行更改,它应该可以正常工作。虽然你可能希望在将包含用户数据的表单提交到你的服务器之前使用谷歌xss攻击…谢谢你的回答,是的,我完全忘记了这一点,我实际上会更改他的部分,而不是我的部分,所以是“英语”以及调用函数的位置。但是如何让我的提交按钮重定向到这个login.php文件,然后“检查”字段?我还必须删除他的login.php的登录表单,因为我的头上已经有了一个。谢谢你的帮助!真管用!令人惊叹的。我把线程作为解决了非常感谢!关于你之前所说的,我还有一个问题。所以基本上你建议我不要做我们刚刚做的事?我应该包括他的php代码来检查输入,并在我的表单所在的标题中启动会话?有没有办法“确保”你刚才帮助我的方法?再次感谢(编辑:这似乎不是一个我可以批准你的答案,因为它在评论中?)。我将完成优化我的登录php文件,然后一定要研究它!只需更改表单字段的名称以匹配同事表单上的字段即可。如需更改此项:
。对所有输入元素进行更改,它应该可以正常工作。虽然你可能希望在将包含用户数据的表单提交到你的服务器之前使用谷歌xss攻击…谢谢你的回答,是的,我完全忘记了这一点,我实际上会更改他的部分,而不是我的部分,所以是“英语”以及调用函数的位置。但是如何让我的提交按钮重定向到这个login.php文件,然后“检查”字段?我还必须删除他的login.php的登录表单,因为我的头上已经有了一个。谢谢你的帮助!真管用!令人惊叹的。我把线程作为解决了非常感谢!关于你之前所说的,我还有一个问题。所以基本上你建议我不要做我们刚刚做的事?我应该包括他的php代码来检查输入,并在我的表单所在的标题中启动会话?有没有办法“确保”你刚才帮助我的方法?再次感谢(编辑:这似乎不是一个我可以批准你的答案,因为它在评论中?)。我将完成优化我的登录php文件,然后一定要研究它!
<form method="post" action="">

        <div id="username">
            <input type="text" name="txt_username" id="txt_username" placeholder="username" required="" value="" />
        <span class="username_icon"><i class="fa fa-user"></i></span>
        </div>
        <div id="password">
        <input type="password" name="txt_password" id="txt_password" placeholder="password" required="" />
        <span class="password_icon"><i class="fa fa-lock"></i></span>
        </div>
        <div id="stay_connected">
        <input type="checkbox" name="chk_connected" id="chk_connected"> 
        <label for="chk_connected"><span>Stay Connected</span></label>
        </div>
        <div id="submit_button">
        <button type="submit" name="sub_login" id="sub_login"><i id="submit"class="fa fa-long-arrow-right"></i></button>
        </div>
        <div class="feedback">login successful <br />redirecting...</div>

        </form>
<?php 

require_once('config/config.inc.php');
require_once('config/settings.inc.php');
require_once('classes/User.php');
require_once('lib/functions.php');

session_start();

/***********************************************************************************************************/
/********************************* INITIALISATION OF VARIABLES ********************************************/
/***********************************************************************************************************/
$error = "";

/***********************************************************************************************************/
/********************************* DATA TREATMENT **************************************************/
/***********************************************************************************************************/
if(isset($_COOKIE['identifiant']) && !empty($_COOKIE['identifiant']) && isset($_COOKIE['mdp']) && !empty($_COOKIE['mdp'])) {


    $monUtilisateur = User::check($_COOKIE['identifiant'], $_COOKIE['mdp']);

    if($monUtilisateur !== false) {
        $_SESSION['auth'] = $monUtilisateur;
        redirect('index.php');
    }
    else {
        // on supprime les cookies
        setcookie('identifiant');
        setcookie('mdp');

        $error = "The username or password is incorrect.";  
    }

}
else {

    if( isset($_POST['txt_identifiant']) || isset($_POST['txt_mdp']) ) {

        /////////// PRELIMINARY CONTROLS ////////////////////////////////////////////////////////////////////////
        $nbErreurs = isset($GLOBALS['login_nbErreurs']) ? (int)$GLOBALS['login_nbErreurs'] : 0;
        $nbChampsrestantsaremplir = isset($GLOBALS['login_nbChampsrestantsaremplir']) ? (int)$GLOBALS['login_nbChampsrestantsaremplir'] : 0;
        $t_erreurs = array();

        /***********************************************************************************************************/
        /********** USERNAME ************************************************************************************/
        /***********************************************************************************************************/
        if (isset($_POST['txt_identifiant'])) {
            $_POST['txt_identifiant'] = trim($_POST['txt_identifiant']);
            if ($_POST['txt_identifiant'] == '') {
                $nbChampsrestantsaremplir++;
                $t_erreurs['txt_identifiant'] = 'Veuillez saisir votre identifiant';
            }
        }

        /***********************************************************************************************************/
        /*********** PASSWORD *******************************************************************************************/
        /***********************************************************************************************************/
        if (isset($_POST['txt_mdp'])) {
            $_POST['txt_mdp'] = trim($_POST['txt_mdp']);
            if ($_POST['txt_mdp'] == '') {
                $nbChampsrestantsaremplir++;
                $t_erreurs['txt_mdp'] = 'Please enter your password';
            }
        }

        ////////// END OF PRELIMINARY CONTROLS //////////////////////////////////////////////////////////////////////
        $GLOBALS['login_nbErreurs'] = $nbErreurs;
        $GLOBALS['login_nbChampsrestantsaremplir'] = $nbChampsrestantsaremplir ;


        if ($nbErreurs == 0 && $nbChampsrestantsaremplir == 0) {

            $monUtilisateur = User::check($_POST['txt_identifiant'], $_POST['txt_mdp']);

            if($monUtilisateur !== false) {
                // si l'authentification est bonne et que la case est cochee, on cree le cookie
                if (isset($_POST['chk_cookie']) && $_POST['chk_cookie']=="oui") {           
                    // on cree les cookies valide 1 JOUR            
                    setcookie('identifiant', $_POST['txt_identifiant'], time() + 1*24*3600, null, null, false, true);
                    setcookie('mdp', $_POST['txt_mdp'], time() + 1*24*3600, null, null, false, true);
                }
                // sinon on supprime
                else {
                    // on supprime les cookies  
                    setcookie('identifiant');
                    setcookie('mdp');
                }
                //je cree une session
                $_SESSION['auth'] = $monUtilisateur;

                //je redirige
                redirect('index.php');
            }
            else 
                $error = "The username or password is incorrect.";

        }

    }

}
?>
<!doctype html>
<html lang="fr">
<head>
    <meta charset="utf-8">
    <title>Authentification</title>
    <meta name="robots" content="noindex,nofollow" />

    <!-- CSS -->
    <link rel="stylesheet" href="themes/original/css/login.css" />

    <!-- JQUERY -->
    <script src="js/jquery-1.11.0.min.js"></script>

    <!-- SCRIPTS DIVERS -->
    <script src="js/jquery.placeholder.min.js"></script>
    <script>
    $(document).ready(function(){
        $('input[placeholder]').placeholder();
    });
    </script>

    <script>
    $(document).ready(function(){   
        $('#txt_identifiant').focus();                                  
    }); 
    </script>
</head>

<body>

    <div id="content">

        <div id="logo">
            <img alt="logo" src="themes/original/images/logo.png" />
        </div>

        <? if(isset($error)) { ?><p class="error"><?php echo $error ?></p><? } ?>

        <form method="post" action="login.php">

            <div id="identifiant">
                <input type="text" name="txt_identifiant" id="txt_identifiant" placeholder="Identifiant" required="" value="" />
            </div>
            <div id="mdp">
                <input type="password" name="txt_mdp" id="txt_mdp" placeholder="Mot de passe" required="" />
            </div>
            <div id="maintenir">
                <input type="checkbox" name="chk_maintenir" id="chk_maintenir"> 
                <label for="chk_maintenir"><span>Stay connected</span></label>
            </div>
            <div id="soumettre">
                <input type="submit" name="sub_login" id="sub_login" value="Connexion" style="width:100px;" />
            </div>

        </form>

</div><!-- fin de content -->

</body>
</html>