PHP verifies whether username and password are empty

angryTom
Release: 2023-02-28 11:16:02
Original
4226 people have browsed it

PHP verifies whether username and password are empty

php verifies whether the username and password are empty

Many times, our front-end js performs a check on the username and password For non-null verification, the backend needs to verify it again, so as to ensure the security of the data and the robustness of the code logic.

php method to verify that the username and password are empty, the code is as follows:

if (!isset($_POST['username']) || !isset($_POST['password'])) {
  die('缺少用户名密码');
}
if (empty($_POST['username']) || empty($_POST['password'])) {
  die('用户名或密码为空');
}
// 正常逻辑
Copy after login

isset and empty

When judging whether a variable has been declared, you can use the isset function

To determine whether a variable has been assigned data and is not empty, you can use the empty function

To determine if a variable exists and is not empty, first use the isset function, and then use the empty function

Update For more PHP related knowledge, please visit PHP中文网!

The above is the detailed content of PHP verifies whether username and password are empty. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template