Home >Backend Development >PHP Problem >PHP verifies whether username and password are empty

PHP verifies whether username and password are empty

angryTom
angryTomOriginal
2019-11-05 09:24:244231browse

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('用户名或密码为空');
}
// 正常逻辑

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!

Statement:
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