+ 3

Can I create login and logout functions only with PHP?

29th Jul 2021, 4:28 PM
Tree Lover
Tree Lover - avatar
3 ответов
+ 1
yes you can do that by setting and unsetting Sessions here is an example : function logout(){ unset($_SESSION['login']); } function login(string $email,string $password):bool { $user = getUserByEmail($email); if(is_null($user)){ return false; } # checking password if(password_verify($password,$user->password)){ #login is successful $_SESSION['login'] = $user; return true; } return false; }
29th Jul 2021, 4:31 PM
Nima
+ 1
If I understand your question correctly, you'll also want to use Javascript (or jQuery) to provide the front-end functionality of your login system and you'll also want to utilize SQL for your database that stores the user's accounts. You'll use Javascript to obtain the user's information and submission to the server, PHP will take the request and verify the data against the database before allowing user access. I'd also recommend validating the data prior to sending it to your server. Otherwise, the functions itself can be done with PHP, but you'll still need the front-end functionality to be able to call those functions on your server scripts.
29th Jul 2021, 4:47 PM
Jakko Jak
Jakko Jak - avatar
- 2
Yeah you can search on Google you will get get with better explanation
29th Jul 2021, 5:16 PM
A S Raghuvanshi
A S Raghuvanshi - avatar