The first couple of lines includes the database connection file, which contains our database connection credentials, and also the functions file, which contains the functions that we are going to use for user verification. Some of the lines also enable us to initialize variables:
The $err and $errmsg variables are used to collect error messages across the script, and depending on whether there are errors, will be displayed on the login form. The $err variable is of type Boolean, and is initially set to false. In most of the scripts in this application, it will decide whether or not SQL queries can be run. The next couple of lines basically checks to see if the form has been submitted:
//is form submitted?
Then tests to see if the form fields are empty or not:
//check that the form values are not empty, if so, set errormsg value
$errmsg="The username field is empty, please enter a username<br>";
If they are empty, the $err variable is set to true and the $errmsg variable is assigned a error message:
$errmsg .="The password field is empty, please enter password<br>";
Another test is performed on the username that is submitted. The test is to verify that the username is in the correct format. Remember that our usernames must be in the format name.surname:
//check that the username is in correct format
$errmsg .="The username that you entered has a incorrect format.<br>";
The checkformat() function is located in the functions.php file and has the following code:
It makes use of regular expression by matching a pattern against a given string value. You can of course use other ways to verify the username format.
blog comments powered by Disqus