User login authentication

TAG

I'm trying to learn user authentication while I'm building a small user login system.

I was wondering if I'm doing something right in regards to user authentication check with the my code below. Thanks for any input!

If(isset($_SESSION["UserID"])){

}else{

header("Location: page.php");
exit();
}

Or, doing something like this:

If(($_SESSION["UserID"] && $_SESSION["UserToken"])){

}else{

header("Location: page.php");
exit();
}

Token is created using bin2hex with the length the string length of the date.

Both appear to work fine. I just want to know if I'm doing this as intended or is there a better way?

Vladimir Despotovic

Both look fine. Only thing is, that I am guessing you are previously setting those SESSION variables, when user types in his credentials into the login form and clicks on submit button?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Login User with Firebase Authentication

Django user authentication and login problem

React User Context not working with login authentication

User access to login page after authentication

Spring Security JDBC authentication login user error

Login as user hdfs failed:su: Authentication failure

Firebase authentication limit login by the same user

CakePHP Authentication/login with 'Employee' instead of 'User'

User Login Authentication using forms and Django

In Keystone 6, can we disable the user authentication/user login?

Creating flutter Json Login form with user Basic authentication

extend laravel 5 built-in authentication to login only "if user == active"

Is there any way to change username field label in user authentication login page?

Firebase Authentication: get user latest data after login

SwiftUI Game Center authentication doesn't prompt user to login

Google authentication without user login for server-side use only

Access ExpireTimeSpan property of Owin Cookie Authentication to notify user of login expiry

Firebase Authentication on nodejs, how to login a user and use mongodb?

user login authentication SingleOrDefault() or FirstOrDefault() which one to use

User Authentication (Signup & Login) on AWS with Lambda, Cognito or IAM

Instagram API Authentication - Do user have to login using their own accounts?

How to Login, Logout and User Registration through in build Authentication method?

Handle user login with token base authentication (multiple ViewControllers) in Swift

how to implement a user authentication system and create accounts for social network login?

Validate Additional User Field in Login with Laravel default Authentication

Authentication problem while login with Custom User Model in Django

Django User Authentication - Can't pass @login_required decorator

How to show a link after login on the basis of user authentication whether user has a blogging account or not

How to re-login user silently using IdentityServer4 authentication