When our users log in,The username and password are verified by the backend.Moreover, the user login status is also set on the backend.After querying the database,Username and password are correct,A uuid is stored in the session. When each page needs to display the corresponding content according to the login status,Then it is determined whether there is a uuid session, and the uuid is not empty. Such as the login button on the head,Show the login button when not logged in,Display username and avatar after login,These are to determine whether there is a uuid value (in the specific implementation,Relatively more complicated).

Let's take a closer look at this step:

Send username and password to backend ajax After the backend receives the username and password,Query database If the query fails,Returns a json data, such as:{"status":"-1", msg:"The username or password is incorrect"} If the query is successful,Store a value in the session,For example uuid, and then return a json to the front end, such as:{"status":"0", msg:"success"} After the front-end js receives the returned data,Determine the status value. If status == 0, use window.location.href to jump;The other status codes are login failures.Clear the password box,Let users re-enter

For example, if you log in to the homepage successfully,Php or java in the homepage, you need to determine whether there is uuid in the session

  <?php if (isset ($_ session ["uuid"])&! Empty ($_ session ["uuid"])):;?>
    <!-If uuid exists, it is not empty,It means already logged in->
    <a href="#">Mosquito</a>
  <?php else?>
    <!-No login->
    <input type="button" value="login" />
  <?php endif;?>
  • Previous Analysis of the unified exception handling mechanism of the Jersey framework
  • Next AngularJS basic ng-csp instructions