I've decided to split up the Authorization class into 2 segments
- Verifying if user has logged in before and therefore has a $_COOKIE set
- Logging a user in without a $_COOKIE present
The class will have a main() method and a logUserInCookies() method. The latter is invoked prior to any headers being sent and that's the one we're going to be focusing on. We'll visit main() tomorrow.
Overview of the logUserInCookies() portion
- The first method it calls is checkSession() to see if the $_SESSION is already set
- If it is, the code exits; no further action is necessary
- Otherwise, it checks for a $_COOKIE (I named it dino_cookie for this example).
- It calls the checkCookie() to see if the cookie exists in the database, and if it does, it sets the $_username and $_user_type variables to the corresponding data retrieved.
- Also, if results are retrieved, TRUE is returned.
- Going back to logUserInCookies(), if TRUE is returned from checkCookie(), the $_SESSIONS are set through the setSession() method
- If neither the $_SESSION nor the $_COOKIE is available, the code will not do anything and later on the main() method will be invoked to attempt to log the user in based on the credentials that he or she provides.
Comments
Post a Comment