Create a second login page that automatically logs in a user

I have a login page as follows:

<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> 

And here is my session.controller.php file:

Press here

Basically, I want to create a second login page that automatically passes the value to the session controller and logs in. For example, if I go to login-guest.php, I would put the default values ​​for the username and password, and then a jquery click event that automatically logs them when using $("#btn-login").trigger('click');

The problem is that the session controller automatically returns to login.php if the session has expired, and I'm not sure how I could do this. Any help would be greatly appreciated!

+4
source share
3 answers

As you mentioned in your comment, you should know how the user logged in first (login or login-guest), so you will need to have some kind of state for each user.

Now, if you cannot increase the session timeout indefinitely, you will probably need to store the login type somewhere else, like in cookies, or as a query string in your URLs.

In the case of a cookie, it would be something like this:

In the registration section of your login-guest.php :

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

And this is when you send the user to the login page:

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

I don’t think cookies can have an endless life, so I set the validity period to two years, which you can change. Obviously, this will not continue if the user deletes cookies or uses a different browser.

+2
source

You have to solve your problem with an additional field in each login form with the type of login (for example: registered, guest), and with this value, perform the required redirection or any other logic that you need?

You can also save this type of login in a session / cookie for future reference.

0
source

You can add simple hidden input to each form:

 <input type="hidden" name="login_type" value="guest" /> 

Then you redirect depending on what type of login is being done:

 if($_POST['login_type'] == 'guest') { header('Location: login-guest.php'); } else { header('Location: login.php'); } 

Of course, there are nicer solutions, and you should always filter inputs, etc., but for simplicity you go.

0
source

Source: https://habr.com/ru/post/1435863/


All Articles