0

I am a student and was given this part of the code for login page in PHP I cannot understand.

Why do we need to check against this expression:

 if (isset($_POST['login'])  and !empty($_POST['login']) and ($_POST['login'] == 'Login')) {
           include "config.php"; //load in any variables
           $DBC = mysqli_connect("127.0.0.1", DBUSER, DBPASSWORD, DBDATABASE) or die();}

and not just this:

if (isset($_POST['login'])  and !empty($_POST['login']) and ($_POST['login'] == 'Login'))

We are checking that POST is from Loign page by checking if $_POST['login'] == 'Login'. But if it IS from the Login page ( $_POST['login'] == 'Login' is True), it can not be empty anyway. Can it?

Anf if it's not empty but is not from the login page ( $_POST['login'] == 'Login' is False), the whole condition won't be True, hence checking for $_POST['login'] == 'Login' seems enough.

I feel I don't understand some hidden part on how php works maybe. Could you please explain why we need to check if !empty($_POST['login']). Thanks!

0 Answers0