+ 3
Can I create login and logout functions only with PHP?
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;
}
+ 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.
- 2
Yeah you can search on Google you will get get with better explanation