php – 创建第二个自动登录用户的登录页面

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 创建第二个自动登录用户的登录页面脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个登录页面如下:

<form action="?" method="post" id="frm-useracc-login" name="frm-useracc-LOGin" >

    <div id="login-username-wrap" >

        <div class="login-input-ITem left">

            <div class="div-seArch-label left">

                <div id="div-leftheader-wrap">

                    <p class="a-topheader-infotext left"><strong>Username: </strong></p>

                </div>

            </div>

            <div class="login-input-content left div-subrow-style ui-corner-all">

                <input tyPE="text" tabindex="1" name="txt-username" id="txt-username" class="input-txt-med required addr-search-input txt-username left">

            </div>

        </div>

    </div>

    <div id="login-password-wrap" >

        <div class="login-input-item left">

            <div class="div-search-label left">

                <div id="div-leftheader-wrap">

                    <p class="a-topheader-infotext left"><strong>Password: </strong></p>

                </div>

            </div>

            <div class="login-input-content left div-subrow-style ui-corner-all">

                <input type="password" tabindex="1" name="txt-password" id="txt-password" class="input-txt-med required addr-search-input txt-password left">

            </div>

        </div>

    </div>

    <div id="login-BTn-bottom" class="centre-div">

        <div id="login-btn-right">

            <button name="btn-login" id="btn-login" class="btn-med ui-button ui-state-default ui-button-text-only ui-corner-all btn-hover-anim btn-row-wrapper left">Login</button>
            <button name="btn-cancel" id="btn-cancel" class="btn-med ui-button ui-state-default ui-button-text-only ui-corner-all btn-hover-anim btn-row-wrapper left">Cancel</button><br /><br />

        </div>

    </div>

</form>

在这里我的session.controller.PHP文件

Click Here

基本上,我想要做的是创建第二个登录页面,自动将值传递给会话控制器并登录.例如,如果我转到login-guest.PHP,我会将用户名和密码的认值和然后有一个jquery点击事件,使用$(“#btn-login”)自动记录它们.触发器(‘click’);

问题是,如果会话超时,会话控制器会自动返回login.PHP并且我不确定如何实现此目的.任何帮助将非常感激!

解决方法

正如您在评论中提到的,您必须知道用户首先登录的方式(登录登录访客),因此您需要为每个用户提供某种状态.

现在,如果您无法将会话超时增加到无限,则可能需要将登录类型存储在cookie中的其他位置,或者作为URL中的查询字符串.

在cookie的情况下,它将是这样的:

在login-guest.PHP登录部分:

...
$expire = 60 * 60 * 24 * 30 * 24 + time(); // 2 years
setcookie('logintype','guest',$expire);

这是您将用户发送到登录页面的位置:

if(isset($_COOKIE['logintype']) && $_COOKIE['logintype']=='guest'){
    header('Location: login-guest.PHP');
} else {
    header('Location: login.PHP');
}

我不认为饼干可以有无限的生命,所以我设定了两年的到期时间你可以改变.显然,如果用户删除cookie或使用其他浏览器,它将不会持久存在.

脚本宝典总结

以上是脚本宝典为你收集整理的php – 创建第二个自动登录用户的登录页面全部内容,希望文章能够帮你解决php – 创建第二个自动登录用户的登录页面所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。