javascript - 使用模式对话框登录表单让我登录 php 函数

标签 javascript php jquery html twitter-bootstrap

我想要做的是,当我选中对话框中的复选框按钮时,我在其中输入的电子邮件和密码将被保存并重定向到 profile.php。

我的问题是它不起作用,并且输入框中出现错误:

Undefined index: unm and Undefined index: pwd

这里有人可以帮助我解决我的问题吗?

PHP:

<?php
if(isset($_POST['login'])) {
    if(isset($_POST['chkbox'])) {
        setcookie("unm",$_POST['email'],time()+3600);
        setcookie("pwd",$_POST['password'],time()+3600);
    }
    ?>
    <script type="text/javascript">
        window.location="profile.php";
    </script>
    <?php
}
?>

HTML:

<a data-toggle="modal" href="#myModal"><span class="glyphicon glyphicon-user"></span> Login</a>

        <div class="container">
            <div class="row">
                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <h5 class="modal-title">PLEASE ENTER YOUR EMAIL ADDRESS AND PASSWORD TO LOG IN.</h5>
                                </div>
                                <div class="modal-body">
                                    <form class="form-horizontal">
                                        <div class="form-group">
                                            <label for="email" class="col-sm-2 control-label">Email</label>
                                            <div class="col-md-9">
                                                <div class="input-group">
                                                    <span class="input-group-addon"><i class="fa fa-envelope-o fa-fw"></i></span>
                                                    <input type="text" name="email" value="<?php echo $_COOKIE['unm'] ?>" class="form-control" placeholder="Enter Email Address..." />
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="password" class="col-sm-2 control-label">Password</label>
                                            <div class="col-md-9">
                                                <div class="input-group">
                                                    <span class="input-group-addon"><i class="fa fa-key fa-fw"></i></span>
                                                    <input type="password" name="password" value="<?php echo $_COOKIE['pwd'] ?>" class="form-control" placeholder="Enter Password..." />
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-sm-offset-2 col-sm-10">
                                                <input type="checkbox" name="chkbox" value="staylogged" class="checkbox-inline" />
                                                <label>  &nbsp; Keep me logged in</label>  &nbsp; <b>|</b>
                                                <a href="" style="text-decoration:none">  &nbsp; Forgot your password?</a>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-sm-offset-2 col-sm-10">
                                                <button type="submit" name="login" class="btn btn-primary"><span class="glyphicon glyphicon-user"></span> Login</button>
                                                <button type="button" id="show_signup_md" class="btn btn-info" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-list-alt"></span> Register</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
            </div>
        </div>

最佳答案

首先检查 $_COOKIE['pwd'] 或 $_COOKIE['unm'] 在 html 中设置,然后再回显它们:

if(isset($_COOKIE['pwd']) && !empty($_COOKIE['pwd'])){
    $pwd = $_COOKIE['pwd'];
}else{
    $pwd = '';
}
//same for unm 

if(isset($_COOKIE['unm']) && !empty($_COOKIE['unm'])){
    $unm = $_COOKIE['unm'];
}else{
    $unm = '';
}

那么输入应该是:

<input type="text" name="email" value="<?php echo $unm ?>" class="form-control" placeholder="Enter Email Address..." />                                    
 //same for pass 
<input type="password" name="password" value="<?php echo $pwd ?>" class="form-control" placeholder="Enter Password..." /> 

下一步不要在 cookie 中存储用户详细信息! 。如果这样做,请使用散列字符串。

关于javascript - 使用模式对话框登录表单让我登录 php 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23746623/

相关文章:

javascript - 查找特定类上方列表项的第一次出现 - JQuery

javascript - 主菜单动态居中下拉

php - 将三个表连接在一起 SQL PHP

javascript - 使用 jQuery 出现的模板化元素之一的正确遍历是什么?

javascript - 如何取消绑定(bind)特定的事件处理程序

php - 将两个旧表中的数据插入到新表中

php - 每 1/10 秒网页上的随机词

javascript - 纵向屏幕有 2 页,但应该只显示其中一页

javascript - 为什么 ~/在脚本引用中不起作用?

javascript - 是否可以使用 jQuery 过滤已获取的数据