Logging into a site is all well and good, but unless the user has an account on the site, logging in is useless. A registration page makes it easy as pie for someone to join a webpage.
The first step to registering is giving your information. But once that's done, it has to submitted and validated. And validation doesn't just prevent incorrect or meaningless information being stored. It also prevents invalid information from being stored, and causing a database crash.
To start, if one tries to store information that's either too long, or in the wrong format, it'll cause the database (PostgreSQL) to output error messages, and it'll refuse to store any information at all.
In the case of primary keys, one must also ensure the same key doesn't already exist in the database.
Using PHP functions such as strlen
will help check to make sure nothing was entered that's beyond the table's pre-defined limits of length, and that any data such as usernames and passwords, were long enough. After all, a username of 'z' is just not on.
Another function, strcmp
, will compare two strings, and output 0 if they are equal. This is necessary, because a simple comparison operator may not cast the variables correctly. It may also be necessary, due to some interesting and unusual behaviours that may crop up, to use the identical operators (===
, and !==
) as opposed to the equal operators (==
, and !=
).
Then there's preg_match
, which can compare a string against any regular expression. For instance, the regular expression '#[0-9]#
' will find any string that contains any number, in any way. Which I used because a name can't have a number.
Finally, filter_var
will filter any string to any parameters one desires, such as the FILTER_VALIDATE_EMAIL
filter, which is built into PHP and will check to see if a string is in the proper email format. Oh, and by the way, there are dozens of filters available.
So after all that, once the data passes validation, all that's left is to send it to the database, with an INSERT
statement, and redirect the user to the login page. Since they have no need to register any more.