Hello!

I am interested in how authentication and redirection of registered users occur when accessing the main page.

Scenario:

  1. user drives https: // mysite and gets on the registration form
  2. the user has registered and got into his personal account, for example: http: //mysite/mycab.php
  3. the user closed the browser, went for a walk, and again he needs to go to the site, he drives in http: // mysite and ???

How to make it immediately hit the http: //mysite/mycab.php

I use cookies based authentication.

Apparently, when loading somewhere on the page with the form you need to check cookies. Previously, this did not work, t.ch. I hope for help. Thank!

  • if (logged in) {header ('Location: http: //mysite/mycab.php')} - Invision
  • @Invision, and exit forgot: R - Visman
  • @Invision, thanks! And how is this "logged in" check? And the header in which part should be located? - Ivan Tikhonov

1 answer 1

In a nutshell, this can be done in 2 ways:

  1. using js
  2. using php

In fact, everyone decides for himself how it is more convenient to do. Due to the fact that no code is provided, I can only answer purely theoretically

  1. РНР option: When accessing the index.php page, after the session_start made, a check is made for the set cookie in which the user ID is contained. And if it is, it’s done <?php header('Location: хттп://mysite/mycab.php'); exit(); ?> <?php header('Location: хттп://mysite/mycab.php'); exit(); ?>

  2. option with JS : the meaning is the same, but the test is on the client side. And just make de there and redirect. BUT! Validation should still be on the server side and check the existence of the user in the database.