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!