'; echo ''; echo ''; echo 'ChurchMapped Registration - Personal account'; echo ' '; echo ' '; echo ' '; echo ' '; echo ''; echo ''; echo ''; echo ''; echo ''; echo ' '; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ' '; echo ''; echo ' '; echo ''; echo ''; echo ''; $errors = array(); #The errors array contains all the issues that might arise during registration of the form. If there are no issues, we enter the data into the database. # Use parameterised queries for cybersecurity purposes. echo '
'; echo '
'; #Don''t forget to add ChurchMapped logo here. echo 'Please see our privacy policy for information on how we manage your data. By registering on the ChurchMapped platform, you confirm that you have read the privacy policy, agree with it, and give us your consent into how we manage your data as outlined in the privacy policy. * indicates required'; echo '
'; echo '
'; echo '
'; #This begins the form for the personal user. We leave the action field blank because we want it to be the case that the user still remains on the page. # For the salutation, we have to ensure that the user is honest. In our view, the following salutations require no extra validation from us: # - Mr # - Mrs # - Miss # - Ms # - Mlle # - Dr # - Sir # - The following salutations *do* require us to do extra checks because of their nature regarding the extra trust they command from users. These are: # - His Eminence # - His Highness # - Her Highness # - Beatitude # - Fr. # - Monsignor # - Deacon # - Mother # - Sister # - Brother # - Canon # - President # - Vice President # We do not check for "Judge", "Deputy District Judge" and "Recorder" because these are not protected titles per se (e.g. Judge Rinder, even though he is not a judge). # Where a user uses a protected salutation, we add the value 1 to the column whether_user_requires_extra_authorisation. Otherwise, if the user does not use a protected salutation, we simply leave the column as NULL. Where a user uses a protected salutation, a mail has to be sent to support@churchmapped.com. This contains details of the registration form that has been submitted. We then send an email to the user (not auto-generated) inquiring into the authenticity of the user; we may also use a phone call too. Once we are satisfied that the user is indeed what they claim, we manually set the row in the column whether_user_requires_extra_authorisation to "2". if(isset($_POST['salutationOfPersonalUser'])){ #The pattern we use throughout this form is to first check whether a submission has been made for a particular field. If not, then we "echo" out a blank field. If so, then we "echo" out what has already been submitted. echo 'Salutation* (Note: Some salutations here require extra validation checks from us before successful registration): '; echo $_POST['salutationOfPersonalUser']; }else{ #This asks for the salutation of the user echo 'Salutation* (Note: Some salutations here require extra validation checks from us before successful registration):' . ' '; #We use the following salutation titles: Mr, Mrs, Ms., Miss, Ms, Mlle, His Eminence, His Highness, Her Highness, Beatitude, Dr., Fr., Monsignor, Deacon, Mother, Sister, Brother, Canon, Dean, Professor, His Honour, Her Honour, Judge, District Judge, Deputy District Judge, Recorder, Lord, President, Vice President, Sir, Dame, Lady, Right Honourable, Don, Dona, Doña, Chief, Officer. Note that the use of "Miss" and "Ms" are not duplicates; there is apparently an important distinction between the two - please refer to external sources for this. Mlle is a French salutation meaning "Mademoiselle"; its English counterpart is "Miss". Note and clear warning: do not include pronouns such as "Mx" - we do not acknowledge this. Do not include titles such as "Sheikh" or "Caliph" - we do not feel it is necessary to include these here. echo ''; } echo '
'; echo '
'; #This asks for the first name of the user. It is a required field. It has a minimum length of 1 and a maximum length of 30. In PHP code, we should also use the utf8_encode() method before inserting it into the database. if(isset($_POST['firstNameOfPersonalUser'])){ echo 'First Name*:' . ' '; echo ''; }else{ echo 'First Name*:' . ' '; echo ''; #Note that we use the pattern attribute here to only permit alphabetical characters and nothing else. Note however that some browsers such as some versions of Safari do not understand this, so we also have to do checks on the server-side too. Update: I've since removed the pattern because some users have names that use characters out of the scope of the alphabet (for example, D'Angelo, which uses an apostrophe). Instead, what we will do in the code down below in the PHP section is that we will use preg_match() and if the preg_match does not return successful for a name that has *at least* one alphabetical caharcter, then we can be sure that we are dealing with what appears to be a name. Update: I realised I can still do this in HTML and so have added the pattern attribute [A-Za-z]+ which means (or at least, I think!) find at least one instance of any character A-Za-Z (basically the entire alphabet). If it can't find this, then this is an indication that we are probably not dealing with a name because practically every name has at least one alphabetical character. Nevertheless, we should check for this as well in PHP code. } echo '
'; echo '
'; #This asks for the middle name of the user. It has a maximum length of 30, as we do not foresee a middle name being longer than 30 characters. It is an optional field. In PHP code, we should also use the utf8_encode() method. if(isset($_POST['middleNameOfPersonalUser'])){ echo 'Middle Name:' . ' '; #NOTE: We *do not* use the "Middle Name" for the CN parameter. Furthermore, we set this as an optional field, compared to first name and surname, as evident from the fact those two fields have the "required" echo ''; }else{ echo 'Middle Name:' . ' '; echo ''; } echo '
'; echo '
'; #This asks for the surname of the personal user. It is a required field. It has a maximum length of 30 characters. In PHP code, we should also use the utf8_encode() method. # Note that in some cultures, for instance Indonesia, people do not have surnames. We will still make this field a required field in any event, but in our errors() array we explicitly state something to the effect of, "We understand that in some cultures, people do not use surnames. If you think this applies to you, please email support@churchmapped.com. Please also contact support@churchmapped.com if you believe this is an error". if(isset($_POST['surnameOfPersonalUser'])){ echo 'Surname*:' . ' '; echo ''; #We use the pattern attribute to ensure that at least one alphabetical character appears in the surname field. If it doesn't, then this is an indication that it is probably not a real surname. }else{ echo 'Surname*:' . ' '; echo ''; } echo '
'; echo '
'; #This asks whether a user is male or female. Note: We do not use "Other". We also check to see if the form has been submitted already. If it has, we try to see if the user has selected "Male" or "Female". If the user has selected "Male", we set the radio button to the default of "Male" (by using the checked attribute); if the user has selected "Female", we set the radio button to the default of "Female" (by using the checked attribute). #Watch out for the value attribute! We do not use "Male" and "Female". Rather, we use an integer - be it 1 or 2 - because the datatype in the database for the column sex_of_user_on_churchmapped is TINYINT(1). The value is as follows: 1 indicates female and 2 indicates male. #This is a required field. However, we should make it clear here that in order to make the Gender radio buttons required, we only need to make one of the radio buttons required. We do that here for the female radio button because it has the value of 1. if(!isset($_POST['genderOfPersonalUser'])){ echo 'Gender*:' . ' '; echo ''; echo ''; echo ''; echo ''; } elseif($_POST['genderOfPersonalUser'] == "2"){ #Here we deal with the scenario where a user has selected male (i.e. 2) echo 'Gender:' . ' '; echo ''; echo ''; echo ''; echo ''; }elseif($_POST['genderOfPersonalUser'] == "1"){ #Here we deal with the scenario where a user has selected female (i.e. 1) echo 'Gender:' . ' '; echo ''; echo ''; echo ''; echo ''; } echo '
'; echo '
'; #We use this section to ask the user for their date of birth. Note that for most versions of Safari as well as Internet Explorer, there is no support for the input type "date", so we have to think of a work around. Also note that we should detect if the user is younger than 18. If they are, we add to the $errors[] array and state that the user must be older than 18 years old to use the ChurchMapped platform. The corresponding column in the table is date_of_birth_of_personal_churchmapped_user. One possible workaround that will work for all browsers is that instead of using the "date", we use three input text fields asking the user for day, month and year respectively. We then concatenate them together with a hyphen and then add them to a database after doing our checks. # Important note: We should review the checkout.php page in light of this discovery. #We use this brief segment as thresholds for ages we can accept - either for legal reasons (as in the case of $minimumAge, where we only permit users 18 and older) or because the age seems spurious (as in the case of $maximumAge, where we do not permit values older than 125 years old). Note that for the HTML code, be careful not to get confused - $minimumAge should go in the input number field max (because this is the maximum value we will permit otherwise it seems as if it's spurious data), and $maximumAge should go in the input number field min (because a user has to be *at least* 18 to join). By using the date() function together with the parameter "Y", which gives the year, we can be sure the code will be dynamically updated rather than us having to update it each and every time. $minimumAge = date("Y") - 18; #We set the minimum age to 18 per our Terms and Conditions. $maximumAge = date("Y") - 125; #Strictly speaking, we don't have a maximum age - if a person is 100 years old, they can still join. The reason we have this here is another way of input validation. The oldest person is around 120 or so, so if a person enters a date of birth that would give them a ridiculously high age like 450, we know something must be wrong. # To reiterate, we use the input type number rather than date because some browsers, such as Safari, unfortunately do not support the date input type. if(!isset($_POST['dayOfBirthOfPersonalUser'])){ #If the *day* of birth of the personal user has no value, we echo all three fields but with the month and year filled in with the previous values. echo 'Date of birth:'; echo '
'; echo '' . ' ' . '' . ' ' . ''; #In PHP code, be sure to use the checkdate() function to ensure that the date is actually valid (for instance, "31st February" would be an invalid date). Note that the checkdate() function accepts dates in the format of MM-DD-YYYY, so be sure to rearrange this before continuing. In PHP code, also be sure to check that the values entered into these boxes are in fact integers, otherwise it is possibly an SQL injection attack or something similar; this is already done to some extent by using the input type "number" as opposed to "text". Note as well how we use the HTML min and max in a first attempt to ensure that the date is valid. Be careful to ensure that the values in min and max don't have spaces besides them, otherwise it could potentially throw our code off. echo '
'; echo 'D = Date; M = Month; Y = Year'; } elseif(!isset($_POST['monthOfBirthOfPersonalUser'])){ #If the month of birth of the personal user has no value, we echo all three fields but with the day of birth and year of birth filled in. echo 'Date of birth:'; echo '
'; echo '' . ' ' . '' . ' ' . ''; echo '
'; echo 'D = Date; M = Month; Y = Year'; }elseif(!isset($_POST['yearOfBirthOfPersonalUser'])){ #If the year of birth of the personal user has no value, we echo all three fields but with the day of birth and month of birth filled in. echo 'Date of birth:'; echo '
'; echo '' . ' ' . '' . ' ' . ''; echo '
'; echo 'D = Date; M = Month; Y = Year'; } elseif(!isset($_POST['dayOfBirthOfPersonalUser']) && !isset($_POST['monthOfBirthOfPersonalUser']) && !isset($_POST['yearOfBirthOfPersonalUser'])){ #If none of the fields relating to the day of birth, month of birth or year of birth have been filled in, we echo all three fields but with no values. echo 'Date of birth:'; echo '
'; echo '' . ' ' . '' . ' ' . ''; echo '
'; echo 'D = Date; M = Month; Y = Year'; } elseif(isset($_POST['dayOfBirthOfPersonalUser']) && isset($_POST['monthOfBirthOfPersonalUser']) && isset($_POST['yearOfBirthOfPersonalUser']) ){ #If all three fields relating to the day of birth, month of birth and year of birth have been filled in, we echo all three fields together with their submitted values. echo 'Date of birth:'; echo '
'; echo '' . ' ' . '' . ' ' . ''; echo '
'; echo 'D = Date; M = Month; Y = Year'; } echo '
'; echo '
'; # This asks the user for a handle. Note that we have a number of requirements for a handle on ChurchMapped: # They must be a minimum of 1 character and a maximum of 20 characters. # They are not allowed to contain the word "God", "ChurchMapped", "Admin" or "Null" # Communicate to the user that it is against the Terms & Conditions for a user to use an expletive in their handle is against the Terms and Conditions of using the website # Handles may only contain alphanumeric characters and an underscore. # Handles must be unique. No two users may have the same handle. # The handle must not contain the "@" character - we will add that ourselves! # This is a required field # The handle must be unicode-compliant. This is because of regular expressions, which by and large only work with Unicode characters. if(isset($_POST['churchmappedHandleOfPersonalUser'])){ echo 'ChurchMapped Handle:' . ' ' . '@' . ''; #We use the JavaScript method onkeyup to check if the handle already exists on the database. We use the pattern [a-zA-Z]+ because we expect a ChurchMapped handle to have at least one alphabetical character. echo '
'; echo 'Note that your handle must be Unicode-compliant.'; }else{ echo 'ChurchMapped Handle:' . ' ' . '@' . ''; #We use the JavaScript method onkeyup to check if the handle already exists on the database. We use the pattern [a-zA-Z]+ because we expect a ChurchMapped handle to have at least one alphabetical character. echo '
'; echo 'Note that your handle must be Unicode-compliant.'; } echo '
'; echo '
'; #We use the HTML input type "email" as one source of input validation. According to official documentation, on browsers that don't support inputs of type email, a email input falls back to being a standard text input. We should still use PHP's email validation to ensure that it is in fact an email. We set a maxlength to 40 characters as, in our view, an email shouldn't have more characters than this. We also set a minlength to "1" character just to ensure again the user has submitted something that looks like an email. Note that this is a required field. We also use the JavaScript onkeyup() to see if the email is already on the database or not. The email address is a required field. if(isset($_POST['emailOfPersonalUser'])){ echo 'Email*:' . ' ' . ''; echo '
'; echo '
'; }else{ echo 'Email*:' . ' ' . ''; echo '
'; echo '
'; } #This is for the password of the user. Always remember to use a hashing algorithm like md5() on this field, together with a SALT which is known only to us, before inserting into the database. Furthermore, we need to check that the password is actually "strong". For us, a password must contain the following, in addition to complying with a minimum of 6 characters and a maximum of 15 characters: # - It must contain at least one special character # - It must contain at least one letter from the alphabet # - It must contain at least one number # We use the input type "password" to ensure that characters that are entered into this field appear as bullet points. This prevents people from "watching over someone's shoulder" to obtain a password. # We should also require that passwords are changed every 6 months for cybersecurity purposes. We can do this with [come back to this later] # This is a required field. echo 'Password*:' . ' ' . ''; echo '
'; echo '
'; #This field ensures that both passwords are the same. It must be the same as the password field above. Therefore, in the PHP code, we have to equate the two together with the hash to ensure that they are the same. If not, we add this too to the errors array. echo 'Confirm Password*:' . ' ' . ''; echo '
'; echo '
'; #This field regards the country of the residence of the ChurchMapped user. We select all the countries in the database churchma_GEOGRAPHY by accessing the database. This is a required field. if(isset($_POST['countryOfPersonalUser'])){ #This section governs the situation where a user has entered information relating to their country. If they have already submitted the information, we echo the '; while($row = mysqli_fetch_array($resultOfQueryToSelectAllCountries, MYSQLI_ASSOC)){ if($row['country_id'] == trim($_POST['countryOfPersonalUser'])){ #Here we check to see if the particular row is equal to what has been posted. If that is the case, we echo this option value but set it as the default option. Remember that we use $row['country_id'] rather than $row['country_name_english'] because this is the actual value that is posted. echo ''; #This sets the default value } else{ echo ''; } } echo ''; }else{ echo 'Country of residence:*' . ' '; $queryToSelectAllCountries = "SELECT country_id, country_name_english FROM churchma_GEOGRAPHY.countries"; #This line obtains the list of countries from the database called churchma_GEOGRAPHY and the table countries. We use the method utf8_encode() because some country names have foreign characters and without using this method, the characters would not appear properly. $resultOfQueryToSelectAllCountries = mysqli_query($conn, $queryToSelectAllCountries); $numberOfCountries = mysqli_num_rows($resultOfQueryToSelectAllCountries); #We use this line of code to get the number of countries. This is used later down in the code where we try to validate user input: if the value posted is greater than the number of countries that actually exist, then we know the value is spurious and it's possible the user is attempting to hack into our systems. echo ''; } echo '
'; echo '
'; #This asks the user about the continent in which they reside. We have to ask this because some countries are in two continents - e.g. Russia is in Europe and Asia; Turkey is in Europe and Asia, and so on. Furthermore, there are cases where a country is not listed here - e.g. Curacao - in which case the user should answer that their country of residence is the Netherlands but that the continent they are in is North America (though some argue that Curacao is in South America). if(isset($_POST['continentOfPersonalUser'])){ echo 'Continent of residence:*' . ' '; echo ''; } else{ echo 'Continent of residence:*' . ' '; echo ''; } echo '
'; echo '
'; #Here we ask the user for the country in which they work. It sometimes happens that a person might live in one country, and work in another (for example, to live in France and work in Switzerland; to live in Luxembourg and work in Belgium). This is an *optional* field. if(isset($_POST['countryOfWorkOfPersonalUser'])){ #This section governs the situation where a user has entered information relating to their country. If they have already submitted the information, we echo the '; while($row = mysqli_fetch_array($resultOfQueryToSelectAllCountries, MYSQLI_ASSOC)){ if($row['country_id'] == trim($_POST['countryOfWorkOfPersonalUser'])){ #Here we check to see if the particular row is equal to what has been posted. If that is the case, we echo this option value but set it as the default option. We use the utf8_encode() method to ensure that values on the database that are not UTF-8 compliant are equated with what has been posted, which is UTF-8 compliant (see the code in the else(){} code where the user has not submitted anything relating to their country). echo ''; #This sets the default value } else{ echo ''; } } echo ''; }else{ echo 'Country of place of work:' . ' '; $queryToSelectAllCountries = "SELECT country_id, country_name_english FROM churchma_GEOGRAPHY.countries"; #This line obtains the list of countries from the database called churchma_GEOGRAPHY and the table countries. We use the method utf8_encode() because some country names have foreign characters and without using this method, the characters would not appear properly. $resultOfQueryToSelectAllCountries = mysqli_query($conn, $queryToSelectAllCountries); echo ''; } echo '
'; echo '
'; #Here we ask the user for the continent of the place they work. It sometimes happens that a person can live in one continent, but work in another - for example, someone who lives in Greece but works in Turkey lives in Europe and works in Asia. if(isset($_POST['continentOfWorkOfPersonalUser'])){ echo 'Continent of work:' . ' '; echo ''; }else{ echo 'Continent of work:' . ' '; echo ''; } echo '
'; echo '
'; #Here we ask the user for the first line of their address. This is a required field. We only accept a minimum length of 1 and a maximum length of 50. if(isset($_POST['addressLineOneOfPersonalUser'])){ echo 'Address line 1*:' . ' '; echo ''; } else{ echo 'Address line 1*:' . ' '; echo ''; } #Here we ask the user for the second line of their address. This is an optional field. We only accept a minimum length of 1 and a maximum length of 50. echo '
'; echo '
'; if(isset($_POST['addressLineTwoOfPersonalUser'])){ echo 'Address line 2:'. ' '; echo ''; #Because address line two is not a required field, we do not have to set a minlength. }else{ echo 'Address line 2:'. ' '; echo ''; #Because address line two is not a required field, we do not have to set a minlength. } echo '
'; echo '
'; #Here we ask the user for the third line of their address - this is usually the county or state, and we should mention this in the placeholder. It is an optional field. It has a minimum length of 1 and a maximum length of 50. if(isset($_POST['addressLineThreeOfPersonalUser'])){ echo 'Address line 3:' . ' '; echo ''; #Because address line three is not a required field, we do not have to set a minlength. } else{ echo 'Address line 3:' . ' '; echo ''; #Because address line three is not a required field, we do not have to set a minlength } echo '
'; echo '
'; #Here we ask the user for the city that they are from - for example, London, Paris, Seattle, and so on. It is a required field. It has a minimum length of 1 and a maximum length of 50. if(isset($_POST['cityOfPersonalUser'])){ echo 'City*:' . ' '; echo ''; #We use the pattern [a-zA-Z]+ to ensure that the city contains at least one alphabetical character. }else{ echo 'City*:' . ' '; echo ''; #We use the pattern [a-zA-Z]+ to ensure that the city contains at least one alphabetical character. } echo '
'; echo '
'; #Here ask the user for their postcode/zip code. It is not a required field because some places in the world do not have a postcode - for example, the Republic of Ireland has many places without postcodes at all. There is a minlength of 1 here and a maxlength of 15, as there is no reason why if(isset($_POST['postcodeOfPersonalUser'])){ echo 'Postcode/Zipcode:' . ' '; echo ''; #Note that "size" here refers to the visual appearance of the form, not what can actually be submitted. } else{ echo 'Postcode/Zipcode:' . ' '; echo ''; } echo '
'; echo '
'; #Towards the end of the form, we have to ask the user that they agree to the Terms & Conditions of using the website. We have to also ask that they agree to the privacy policy. #Here we ask if they agree to the Terms and Conditions. Don't forget that the value on the database is a number, representing the version of the Terms and Conditions. We use the HTML tags to ensure that the Terms and Conditions can appear to the user without redirecting the user to an external link. However, there is one important difference between Terms & Conditions (as well as Privacy Policy) and the other input elements and it is that we do not add a name and value attribute to the textarea. This is because for the Terms & Conditions as well as the Privacy Policy, we are more interested in the version/ID number rather than the actual text - we already have the text on the database. Furthermore, the datatype on the database for the columns version_of_terms_and_conditions_agreed_to_by_churchmapped_user and version_of_privacy_policy_agreed_to_by_churchmapped_user are SMALLINT. To get around this, we use a checkbox instead, and this is what we use in the PHP code. We also use the "disabled" attribute for the respective textareas to prevent the user from tampering with the text in the terms and conditions. Kindly note (this is good news) that disabling the textarea does not at all prevent scrolling. echo 'Terms & Conditions:'; echo '
'; echo 'The terms and conditions can also be read on the ChurchMapped legal page here'; #We include a reference here to the Terms & Conditions on the legal page of ChurchMapped because the textarea might be too small for some readers. echo '
'; echo ''; echo '
'; echo '
'; echo 'Do you agree to the terms and conditions? Please check the box to indicate agreement (note: in order to register on the ChurchMapped platform, you must agree with our Terms and Conditions)'; echo ''; #This is what we actually use in the PHP code. We have manually added the value of 1. Whenever we add a new Terms and Conditions or Privacy Policy, we have to amend the value of this checkbox manually. Note that unlike the other inputs here, we always echo the checkbox without a check if a user has submitted information that has not passed our validation checks. This is to comply with GDPR requirements (namely, to avoid the accusation that we have opted the user in by default, which is not allowed). echo '
'; echo '
'; echo 'Privacy policy:'; echo '
'; echo 'The privacy policy can also be read on the ChurchMapped legal page here'; echo '
'; echo ''; #We use the text "Lorem ipsum, etc" purely for local testing purposes. In production code, we include the actual Privacy Policy here. echo '
'; echo 'Do you agree to the privacy policy? Please check the box to indicate agreement (note: in order to register on the ChurchMapped platform, you must agree with our privacy policy)'; echo ''; #Note that unlike the other inputs here, we always echo the checkbox without a check if a user has submitted information that has not passed our validation checks. This is to comply with GDPR requirements (namely, to avoid the accusation that we have opted the user in by default, which is not allowed). echo '
'; echo '
'; echo ''; echo '
'; #This ends the form for the personal user. echo '
'; #Here we ask the user if they have forgotten their password. If they press or click this, they are directed to forgottenpassword.html (in the local version, this is forgottenpassword.php.) We use the script to redirect the user to Forgotten Password page. This part is powered by the redirectjs script # In the PHP code, don't forget that before inserting an IP address into the column ip_address_at_point_of_registration, we use PHP's IP validation function to prevent any SQL injection attack. #Here we create two arrays - one to check for whether the handle is available and the other to check if the email is available. Later on in the code we check if these arrays are empty or not. If they are not empty, this indicates that the handle or the email (whatever the case may be) has already been taken and we therefore issue an errors statement. The first array is called $checkIfChurchMappedHandleIsAvailable. The second array is called $checkIfEmailIsAvailable. $checkIfChurchMappedHandleIsAvailable = array(); $checkIfEmailIsAvailable = array(); #Here we deal with the ChurchMapped handle $stmt = $conn->prepare("SELECT handle_of_user_on_churchmapped FROM churchma_USERS_ON_CHURCHMAPPED.user_details_on_churchmapped WHERE handle_of_user_on_churchmapped LIKE ?"); #Here we select the column handle_of_user_on_churchmapped from the table user_details_on_churchmapped in the database churchma_USERS_ON_CHURCHMAPPED. We use parameterised queries for extra cyber security. However, we should note here that using mysqli_num_rows works somewhat "strangely" when using prepared statements. if(isset($_POST['churchmappedHandleOfPersonalUser'])){ #We use the isset() function to ensure that we do not receive a PHP notice that the index cannot be found $valueOfChurchMappedHandleToSearch = trim("%" . $_POST['churchmappedHandleOfPersonalUser'] . "%"); #This is the actual ChurchMapped handle. } $stmt->bind_param("s", $valueOfChurchMappedHandleToSearch); #The first parameter "s" indicates that we are expecting a string, which is what churchmappedHandleOfPersonalUser is. $stmt->execute(); #This finally executes the prepared statement $stmt_result = $stmt->get_result(); #This is the first step in helping us get the number of rows. if($stmt_result->num_rows>0){ #Here we see if the number of rows is greater than 0. If it is, then this is an indication in the code down below that the handle has already been taken. while($row = $stmt_result->fetch_assoc()){ $checkIfChurchMappedHandleIsAvailable[] = $row['handle_of_user_on_churchmapped']; #Here, fill up the array $checkIfChurchMappedHandleIsAvailable with all the results that have been found. # We issue an errors statement in the code later down below. } } #Here we deal with the email address to check whether the email address has already been used. $stmtToGetEmail = $conn->prepare("SELECT primary_email_of_user_on_churchmapped FROM churchma_USERS_ON_CHURCHMAPPED.user_details_on_churchmapped WHERE primary_email_of_user_on_churchmapped LIKE ?"); if(isset($_POST['emailOfPersonalUser'])){ $valueOfEmailToSearch = trim("%" . $_POST['emailOfPersonalUser'] . "%"); #This is the email of the user to search } $stmtToGetEmail->bind_param("s", $valueOfEmailToSearch); $stmtToGetEmail->execute(); #This finally executes the prepared statement. $stmt_result_for_email = $stmtToGetEmail->get_result(); #This is the first step in helping us get the number of rows to obtain the email. if($stmt_result_for_email->num_rows > 0){ while($row = $stmt_result_for_email->fetch_assoc()){ $checkIfEmailIsAvailable[] = $row['primary_email_of_user_on_churchmapped']; #Here we fill up the array $checkIfEmailIsAvailable with all the results that have been found # We issue an errors statement in the code later down below. } } # In the PHP code, don't forget to use trim() to remove whitespace from the left hand side of what has been posted as well as the right hand side. $patternForAlphabeticalOrder = "/[a-zA-Z]+/"; #This is the pattern that we use for fields where we expect to see at least one alphabetical character, such as the field for the first name. To recap, this pattern means any character between a-z and A-Z must occur at least once. $patternForSpecialCharacters = '/\W/'; #This regular expression matches all special characters, such as !, %, £ and so on. $patternForNumbers = '/[0-9]/'; #This pattern matches all numbers. $patternForChurchMappedUserName = '/ChurchMapped/i'; #We declare a pattern for the ChurchMapped username for the line of code later where we use preg_match() to check if the handle entered has the prohibited word "ChurchMapped" (this is reserved only for us). $patternForConsecutiveCharacters = '/(abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz|012|123|234|345|456|567|678|789)+/'; #This pattern attempts to detect consecutive characters. We use it to prevent users from using consecutive characters for their password. $patternForExpletives = '/(fuck)|(shit)|(bitch)|(pussyhole)|(wanker)/i'; #This is a pattern for expletives. We do not allow expletives in the ChurchMapped handle. Because the list of expletives constantly grows, we need to constantly add to this list and check the database as well. The i modifier here means we are making case-insensitive regular expression matches. Be mindful, however, because it can sometimes happen that a person's name is also an expletive (e.g. Fanny) so we need to communicate to the user that if they think this is a mistake, they should contact support@churchmapped.com. $patternForProhibitedCharacters = '/([^a-zA-Z0-9_])/'; #This pattern matches all characters except lowercase alphabetical characters and uppercase alphabetical characters, numbers (0-9) and an underscore. We use this to prevent handles on ChurchMapped from containing characters outside of those we permit. if(isset($_POST['submitRegistrationFormForPersonalUser'])){ #This area begins the input validation for the registration form once it has been submitted. An important note (added 4th August 2021): in a number of places in our script down below, we use the method strlen() to determine the number of characters. However, this only works with English characters, because strlen() works on the assumption that one character equals one byte. This works fine for English characters, but for foreign characters that are not based in the UTF-8 system, a single "character" could actually take multiple bytes, in stark comparison to English. This is something to bear in mind. We will continue using strlen() for now but rely on the fact that in many instances in our code where we use strlen() we ask the user to contact support@churchmapped.com. # An important note (added 5th August 2021); in a number of places in our script down below, we use is_numeric rather than is_int because posted values that are numerical might not strictly be integers but strings. The is_numeric function is therefore preferable because it considers both strict integers and strings which are purely numeric. ##This segment deals with information entered into the first name field (firstNameOfPersonalUser) if(!isset($_POST['firstNameOfPersonalUser'])){ #If the field for the user's first name is somehow empty, we issue an error notifying them we expect users to register either with their real first name, or a name which they are known as by many in their community. $errors[] = "You need to enter your first name."; } elseif(isset($_POST['firstNameOfPersonalUser']) && (preg_match($patternForAlphabeticalOrder, $_POST['firstNameOfPersonalUser']) == 0 || !preg_match($patternForAlphabeticalOrder, $_POST['firstNameOfPersonalUser'])) ){#Here we make sure that field for the user's first name contains alphabetical letters, otherwise a user could bypass the registration form by entering something nonsensical like "___23271". Note that although the pattern attribute should deal with this, we should still check this on the server-side, and we do this here. Furthermore, some browsers do not support the pattern attribute. The second part of this elseif(){} statement requires some explanation. $errors[] = "This does not seem like a real name. Please enter your real name. Kindly note that it is a condition of our Terms & Conditions that you must use either your real name to register for an account on the ChurchMapped platform or at least a name that many people know you by."; } elseif(isset($_POST['firstNameOfPersonalUser']) && (strlen($_POST['firstNameOfPersonalUser']) < 1 || strlen($_POST['firstNameOfPersonalUser']) > 30)){ #Here we check to see if the information entered into the field firstNameOfPersonalUser (i.e. their first name) is less than 1 character or greater than 30 characters. $errors[] = 'You have either entered a name that is either too short or too long. Names can only be more than 1 character or less than or equal to 30 characters. If you think an exception applies to your case, please contact support@churchmapped.com'; #If the number of characters entered into the field firstNameOfPersonalUser is less than 1 character or more than 30 characters, we add this to the errors array. In the event that a user does in fact have a name longer than 30 characters, we urge them to contact us. We use the mailto attribute to make it easier for the user to contact us. } ##This segment deals with information entered into the middle name field (middleNameOfPersonalUser) elseif(isset($_POST['middleNameOfPersonalUser']) && (preg_match($patternForAlphabeticalOrder, $_POST['middleNameOfPersonalUser']) == 0 || !preg_match($patternForAlphabeticalOrder, $_POST['middleNameOfPersonalUser']))){ #Unlike the first name field, we do not first to check whether or not information has been entered (a la if(!isset($_POST['middleNameOfPersonalUser'])){}) because the middle name of the user is not a required field so we don't have to check for whether information has been entered at all. Instead, we skip to check the following - in a situation where the user has indeed entered information regarding their middle name, does it contain any alphabetical characters or not? If not, then this might mean the middle name is bogus and so we proceed to adding to the $errors[] array. $errors[] = "Your middle name must contain at least one alphabetical character."; } elseif(isset($_POST['middleNameOfPersonalUser']) && (strlen($_POST['middleNameOfPersonalUser']) < 1 || strlen($_POST['middleNameOfPersonalUser']) > 30) ){ $errors[] = 'You have either entered a middle name that is either too short or too long. Middle names can only be more than 1 character or less than or equal to 30 characters. If you think an exception applies to your case, please contact support@churchmapped.com'; #If the number of characters entered into the field middleNameOfPersonalUser is less than 1 character or more than 30 characters, we add this to the errors array. In the event that a user does in fact have a middle name longer than 30 characters, we urge them to contact us. We use the mailto attribute to make it easier for the user to contact us. } ##This segment deals with information entered into the surname field (surnameOfPersonalUser) elseif(!isset($_POST['surnameOfPersonalUser'])){ #Here we check to see if the surname field has been entered. It is a required field. $errors[] = 'You must enter your surname. Here at ChurchMapped, we are truly committed to diversity and cultural understanding and understand that some cultures do not have a surname. If you believe this applies to you, please contact support@churchmapped.com. For anything else, or if you believe this is an error, please also contact support@churchmapped.com.'; } elseif(isset($_POST['surnameOfPersonalUser']) && (preg_match($patternForAlphabeticalOrder, $_POST['surnameOfPersonalUser']) == 0 || !preg_match($patternForAlphabeticalOrder, $_POST['surnameOfPersonalUser']))){ #Here we check to see if the surname contains any alphabetical letters or not. If it doesn't, then it doesn't appear to be a surname and so we issue an error statement notifying the user it doesn't appear to be a surname. $errors[] = 'This doesn\'t appear to be a surname. Please enter a valid surname. If you think this is an error, please contact support@churchmapped.com.'; } elseif(isset($_POST['surnameOfPersonalUser']) && (strlen($_POST['surnameOfPersonalUser']) < 1 || strlen($_POST['surnameOfPersonalUser']) > 30)){ $errors[] = 'You have either entered a surname that is either too short or too long. Surnames can only be more than 1 character or less than or equal to 30 characters. If you think an exception applies to your case, please contact support@churchmapped.com'; } #This begins the segment for the day of the birth of the personal user elseif(!isset($_POST['dayOfBirthOfPersonalUser'])){ #Here we check to see if the user has entered a value for their day of birth. If not, we add to the errors array and inform the user they need to enter a day for their birthday. $errors[] = 'Please enter a day for your birthday.'; } elseif(isset($_POST['dayOfBirthOfPersonalUser']) && !is_numeric($_POST['dayOfBirthOfPersonalUser'])){ #Here we check that the day of birth for the user has been entered and check to see that the day of birth is an integer (days run from 1-31). If not, then we issue a statement in the errors array indicating to the user that they must enter a valid date. $errors[] = 'Please enter a whole number for your birthday'; } elseif(isset($_POST['dayOfBirthOfPersonalUser']) && ($_POST['dayOfBirthOfPersonalUser'] < 1 || $_POST['dayOfBirthOfPersonalUser'] > 31)){ $errors[] = 'Please enter a valid day of the month. Valid dates run from 1 through to 31'; } #This begins the segment for the month of the birth of the personal user elseif(!isset($_POST['monthOfBirthOfPersonalUser'])){ #This checks to see if the month has been filled in for the personal user. $errors[] = 'Please enter a month for your birthday.'; } elseif(isset($_POST['monthOfBirthOfPersonalUser']) && !is_numeric($_POST['monthOfBirthOfPersonalUser'])){ #This checks that in the situation the month of birth the personal user has been entered, that the value is in fact an integer. If it is not, we pass a message to the errors array. $errors[] = 'Please enter a whole number for the month in which you were born.'; } elseif(isset($_POST['monthOfBirthOfPersonalUser']) && ($_POST['monthOfBirthOfPersonalUser'] < 1 || $_POST['monthOfBirthOfPersonalUser'] > 12)){ #Here we check to ensure that a user has not submitted a spurious value - a month cannot be less than 1 (January) or greater than 12 (December) in the prevailing calendar system (Gregorian) $errors[] = 'Please enter a valid month. Valid months run from 1 through to 12'; } #This begins the segment for the year of the birth of the personal user elseif(!isset($_POST['yearOfBirthOfPersonalUser'])){ $errors[] = 'Please enter a year for your birthday'; } elseif(isset($_POST['yearOfBirthOfPersonalUser']) && !is_numeric($_POST['yearOfBirthOfPersonalUser'])){ #This checks whether the year of birth of the personal user is an integer. $errors[] = 'Please enter a whole number for the year in which you were born.'; } # In relation to the year of birth, we check to see if the user is above 18. elseif(isset($_POST['yearOfBirthOfPersonalUser']) && ($_POST['yearOfBirthOfPersonalUser'] > $minimumAge)){ #Here we check to see if the user is above 18 years old. This is done by checking whether the value entered into yearOfBirthOfPersonalUser is greater than the minimumAge, which we calculate by subtracting 18 from the current date (e.g. 2021-18 = 2003). In other words, and using the example of 2021 as the current year, if the user has entered, say, 2004 in yearOfBirthOfPersonalUser, because 2004 > $minimumAge (i.e. 2021-18 = 2003), we issue an error notifying the user that they are too young. $errors[] = 'You must be at least 18 years of age in order to join the ChurchMapped platform.'; } elseif(isset($_POST['yearOfBirthOfPersonalUser']) && ($_POST['yearOfBirthOfPersonalUser'] < $maximumAge)){ #Here we check to see if the age entered is spurious, that is, it is seemingly old like 400 years old then we issue an error *but* inform the user that if the age is in fact accurate, they should contact us on support@churchmapped.com. We calculate the value for $maximumAge by taking the current year and subtracting by 125 (in our view, anything more than 125 years old seems odd, to say the least). If the value entered by the user for yearOfBirthOfPersonalUser is less than the value in maximumAge, we issue the error (e.g. if the user entered 1000 as their birthday and $maximumAge is given by 2021-125 = 1896. In such instances, the date is spurious. $errors[] = 'This doesn\'t seem like a real birth year. If it is in fact accurate, please contact us on support@churchmapped.com'; } elseif(!checkdate(intval($_POST['monthOfBirthOfPersonalUser']), intval($_POST['dayOfBirthOfPersonalUser']), intval($_POST['yearOfBirthOfPersonalUser']))){ #Here we check to see if the date entered is in fact legitimate. For example, based on how our form is constructed, a person could submit a date such as February 31 1982. This might pass the checks above, but the checkdate() function in PHP will invalidate it. This prevents bogus date entries. $errors[] = 'This does not seem to be a real date. Please enter a valid date. If you believe this is an error, please contact us on support@churchmapped.com'; } #This deals with the handle for the ChurchMapped user. Note that in the database itself, we do not use the @ character. Furthermore, note that this is also tested in the AJAX file but all it does is communicate to the user that the handle is not permitted. It is the code down below in PHP that actually prevents the user from using the elseif(!isset($_POST['churchmappedHandleOfPersonalUser'])){ #Here we check to see that the user has entered information into the ChurchMapped user handle field. $errors[] = 'You must enter a handle for your profile on ChurchMapped'; } elseif(isset($_POST['churchmappedHandleOfPersonalUser']) && (strlen($_POST['churchmappedHandleOfPersonalUser']) < 1 || strlen($_POST['churchmappedHandleOfPersonalUser']) > 20)){ $errors[] = 'Your handle is either too short or too long. Handles must be a minimum of 1 character and a maximum of 20 characters. Note that this restriction does not include the \'@\' character'; } elseif($_POST['churchmappedHandleOfPersonalUser'] == "God" || $_POST['churchmappedHandleOfPersonalUser'] == "ChurchMapped" || $_POST['churchmappedHandleOfPersonalUser'] == "Admin" || $_POST['churchmappedHandleOfPersonalUser'] === "NULL" || preg_match($patternForChurchMappedUserName, $_POST['churchmappedHandleOfPersonalUser'])){ #These are banned words that are not allowed on the platform. Note that we use three equal signs with regards to checking for the value "NULL" because we want to communicate to PHP that we are checking *precisely* for the string called NULL. Please look into the difference between two equals signs and three as far as PHP is concerned. $errors[] = 'This is not a permitted handle. Please use another'; } elseif(preg_match($patternForExpletives, $_POST['churchmappedHandleOfPersonalUser'])){ #Here we check for expletives in the ChurchMapped handle. If it contains, or seems to contain a swear word, we issue a statement notifying the user that we do not permit expletives in their handle. However, we have to be mindful of the fact that sometimes foreign names might be swear words in English; to that end, we communicate to the user to contact support@churchmapped.com so that we can look into this manually. $errors[] = 'Please revise your handle. We do not permit expletives in our handles. If you think this is a mistake, please contact support@churchmapped.com and we will look into this for you'; } elseif(preg_match($patternForProhibitedCharacters, $_POST['churchmappedHandleOfPersonalUser'])){ #Here we check to see if the handle contains prohibited characters. We do this by using the pattern ([^a-zA-Z_]) which matches all characters except lowercase and uppercase alphabetical characters and the underscore. If this preg_match returns true, then we know the handle contains a prohibited character and so we issue an error statement. It should be reiterated this regex matches only unicode-complaint characters, which is what we want. $errors[] = 'This is not a permitted handle. Handles may only contain characters from the alphabet (A-Z and a-z), numbers and an underscore. Please revise your handle'; } elseif(!empty($checkIfChurchMappedHandleIsAvailable)){ $errors[] = 'Sadly, it seems that this handle has already been taken. Please consider another'; } elseif(!isset($_POST['emailOfPersonalUser'])){ #We use this to check if the user has entered any information into the email field at all. $errors[] = 'The email address is a required field. Please fill it in'; } elseif(isset($_POST['emailOfPersonalUser']) && (strlen($_POST['emailOfPersonalUser']) < 1 || strlen($_POST['emailOfPersonalUser']) > 40)){ #Here we check for the string length of the email address. Currently we only accept email address with a minimum of 1 character (though I don't even think an email address of 1 character is even possible, and a maximum of 40 characters. $errors[] = 'Your email address appears to be either too short or too long. We can accept input with a minimum of 1 character and a maximum of 40 characters. Please revise'; } elseif(isset($_POST['emailOfPersonalUser']) && !filter_var($_POST['emailOfPersonalUser'], FILTER_VALIDATE_EMAIL)){ #The filter_var function in PHP checks to see if the email address is in fact an email address. If it is not, we issue an error statement. Note, however, that this function is defective in some minor respects because email validation is complicated and so it might reject a perfectly acceptable email. See this on StackOverflow: https://stackoverflow.com/questions/19220158/php-filter-validate-email-does-not-work-correctly. In such instances, we should communicate to the user that they can communicate with support@churchmapped.com and we will look into the issue. $errors[] = 'Your email address appears to be invalid. If this is a mistake, please consult support@churchmapped.com and we will look into this for you'; } elseif(!empty($checkIfEmailIsAvailable)){ #Here we check to see if the email is already in the database $errors[] = 'It seems we already have this email address. Accounts are restricted to one email per user per user type (personal or business). If you have forgotten your password, please press the \'Forgotten Password\' button'; } #Here we check for the password that has been entered and whether it is suitable. Don't forget to hash all passwords. elseif(!isset($_POST['passwordOfPersonalUser'])){ #Here we check to see that the user has in fact entered a password. If not, we issue an error statement. $errors[] = 'Please enter a password. This is a requirement'; } elseif(isset($_POST['passwordOfPersonalUser']) && isset($_POST['confirmPasswordOfPersonalUser']) && strcmp($_POST['passwordOfPersonalUser'], $_POST['confirmPasswordOfPersonalUser']) != 0){ #The strcmp compares two strings. If the value is 0, then they are equal, according to w3Schools. So if it is not equal to 0, then the two strings are unequal. Note that strcmp is case-sensitive. $errors[] = 'The password you entered into the password field is not the same as the password entered into the Confirm Password field. Please check and revise to ensure they are the same'; } elseif(isset($_POST['passwordOfPersonalUser']) && (strlen($_POST['passwordOfPersonalUser'])) < 6 || strlen($_POST['passwordOfPersonalUser']) > 15 ){ #Here we check to ensure that the password length is a minimum of 6 characters and a maximum of 15 characters. $errors[] = 'The password you entered is either too short or too long. Passwords must be between 6 and 15 characters (all inclusive)'; } elseif(isset($_POST['passwordOfPersonalUser']) && (preg_match($patternForAlphabeticalOrder, $_POST['passwordOfPersonalUser']) == 0 || !preg_match($patternForAlphabeticalOrder, $_POST['passwordOfPersonalUser']) )){ #Here we check to see if the password features at least one alphabetical character $errors[] = 'Your password does not contain an alphabetical letter. Please use at least one alphabetical character as your password'; } elseif(isset($_POST['passwordOfPersonalUser']) && (preg_match($patternForSpecialCharacters, $_POST['passwordOfPersonalUser']) == 0 || !preg_match($patternForSpecialCharacters,$_POST['passwordOfPersonalUser']))){ #Here we check to see that the password contains at least one special character $errors[] = 'Your password does not contain any special characters. Please include a special character(s) in your password. Examples of special characters include ! ; £ and so on'; } elseif(isset($_POST['passwordOfPersonalUser']) && (preg_match($patternForConsecutiveCharacters, $_POST['passwordOfPersonalUser']) == 1)){ #Here we check to see that the password does not contain consecutive characters. We have this requirement for cybersecurity purposes and to prevent users from using simple passwords like abc123, and so on. How this works is that if this *does* detect consecutive characters, it we issue an error statement. $errors[] = 'Your password contains consecutive characters. We take cybersecurity at ChurchMapped seriously and therefore cannot allow a password with consecutive characters. Please revise'; } elseif(isset($_POST['passwordOfPersonalUser']) && (preg_match($patternForNumbers, $_POST['passwordOfPersonalUser']) == 0 || !preg_match($patternForNumbers, $_POST['passwordOfPersonalUser']))){ $errors[] = 'Your password does not contain any numbers. Please include at least one number in your password'; } #This begins the segment for the confirmPasswordOfPersonalUser field elseif(!isset($_POST['confirmPasswordOfPersonalUser'])){ #Here we deal with the situation where the user has not entered any information into the Confirm Password field. $errors[] = 'You must enter a value in the Confirm Password field. This is a required field'; } #Because we have already added an elseif(){} statement above to check for whether the password is identical to the information entered into the confirm password field, there is no need to repeat it here for the Confirm Password field because if A = B then B = A. elseif(isset($_POST['confirmPasswordOfPersonalUser']) && (strlen($_POST['confirmPasswordOfPersonalUser']) < 6 || strlen($_POST['confirmPasswordOfPersonalUser']) > 15)){ #Here we check that the confirm password length is a minimum of 6 characters and a maximum of 15 characters. $errors[] = 'To confirm your password, it must be a minimum of 6 characters and a maximum of 15 characters. Please revise'; } elseif(isset($_POST['confirmPasswordOfPersonalUser']) && (preg_match($patternForAlphabeticalOrder, $_POST['confirmPasswordOfPersonalUser']) == 0 || !preg_match($patternForAlphabeticalOrder, $_POST['confirmPasswordOfPersonalUser']) )){ #Here we check to see if the confirm password field features at least one alphabetical character $errors[] = 'The information entered in the Confirm Password area does not contain an alphabetical letter. Please use at least one alphabetical character as your password'; } elseif(isset($_POST['confirmPasswordOfPersonalUser']) && (preg_match($patternForSpecialCharacters, $_POST['confirmPasswordOfPersonalUser']) == 0 || !preg_match($patternForSpecialCharacters, $_POST['confirmPasswordOfPersonalUser']))){ #Here we check to see if he confirm password field contains at least one special character $errors[] = 'The Confirm Password field must contain at least one special character. Please include a special character(s) in the Confirm Password field. Examples of special characters include ! ; £ and so on'; } elseif(isset($_POST['confirmPasswordOfPersonalUser']) && preg_match($patternForConsecutiveCharacters, $_POST['confirmPasswordOfPersonalUser'])){ $errors[] = 'The Confirm Password field contains consecutive characters. We take cybersecurity at ChurchMapped seriously and therefore cannot allow a password with consecutive characters. Please revise'; } elseif(isset($_POST['confirmPasswordOfPersonalUser']) && (preg_match($patternForNumbers, $_POST['confirmPasswordOfPersonalUser']) == 0 || !preg_match($patternForNumbers, $_POST['confirmPasswordOfPersonalUser']))){ $errors[] = 'The Confirm Password field does not contain any numbers. Please revise the Confirm Password area by including at least one number'; } # Careful attention should be paid to this following comment. One of the good things about using option values for countries rather than actual name (i.e. option value = "1" instead of option value = "Afghanistan") is that it deters knowledgable users from tampering with the value because a value *has* to be an integer. If the user gives a value greater than the accepted values (corresponding to the number of countries) e.g. "1000", the value simply won't work. And if a user tries to give a value of less than 1, it won't work either. Now, if we used string values as the option value (e.g. option value = "Afghanistan" instead of option value = "1"), it would allow users to tamper with this and submit spurious values that aren't countries, or even worse, expletives and other things. Integer values prevent this. (Admittedly, there are defence mechanisms that can prevent this (for example, casting all the countries into an array and then checking whether the ), but they are much more complicated than is worth. #This part deals with the country of residence of the user. It is a required field. elseif(!isset($_POST['countryOfPersonalUser'])){ #Here we check to see that the user has actually submitted a country. The country of residence is a required field. $errors[] = 'We need your country of residence. Please provide this in order to join the ChurchMapped platform'; } elseif(isset($_POST['countryOfPersonalUser']) && !is_numeric(intval($_POST['countryOfPersonalUser']))){ #Here we check to see that the countryOfPersonalUser is an integer (we use an integer in the option value because the value on the database for the column country_of_residence_of_user_on_churchmapped is tinyint(3). $errors[] = 'This is not a country we recognise. Please provide a country we recognise. If you believe this is an error, please contact support@churchmapped.com'; } elseif(isset($_POST['countryOfPersonalUser']) && $_POST['countryOfPersonalUser'] < 1){ #Here we check to ensure that the option value is not less than 1 (the first country is Afghanistan - however, note that where a new country has been formed or Afghanistan changes its name, we need to change this too). If it is, this an indication that something is wrong...most likely, the user is trying to tamper with the fields. $errors[] = 'We don\'t recognise this country. The first country we have on our list is Afghanistan. Please review this, or if you think this is a mistake, please contact support@churchmapped.com'; #Where the first country in our database changes (e.g. due to the creation of a new country), then we should change "Afghanistan" to that country. } elseif(isset($_POST['countryOfPersonalUser']) > $numberOfCountries){ #Here we check to ensure that the value entered is not greater than the maximum number of countries we have on our database. If it is, then the value the user posted is spurious. $errors[] = 'We don\'t recognise this country. The last country we have on our list is Zimbabwe. Please review this, or if you think this is a mistake, please contact support@churchmapped.com'; #Where the last country in our database changes (e.g. due to the creation of a new country), then we should change "Zimbabwe" to that country. } # This part deals with the continent of residence of user. It is a required field. elseif(!isset($_POST['continentOfPersonalUser'])){ #Here we check to see if the user has submitted a continent where they live. The continent where they live is a required value. $errors[] = 'You need to fill in the continent that you live in. Please provide the continent in which you live in'; } elseif(isset($_POST['continentOfPersonalUser']) && !is_numeric(intval($_POST['continentOfPersonalUser']))){ #We are expecting an integer for the continent in which the user is based (because the value in the database for the column continent_of_residence_of_churchmapped_user, which is of TINYINT type. $errors[] = 'This is not a continent we recognise. Please provide a continent we recognise. If you believe this is an error, please contact support@churchmapped.com'; } elseif(isset($_POST['continentOfPersonalUser']) && $_POST['continentOfPersonalUser'] < 1){ #Here we check to ensure that the option value for the continent of the residence of the personal user is not less than 1 (the first continent is Africa - however, note that where a new continent has been formed or Africa changes its name, we need to change this too). If it is, this is an indication that something is wrong...most likely, the user is trying to tamper with this value $errors[] = 'We don\'t recognise this continent. The first continent we have on our list is Africa. Please review this, or if you think this is a mistake, please contact support@churchmapped.com'; #Where the first continent in our database (by alphabetical order) changes (e.g. due to the creation of a new continent or the renaming of the continent), then we should change "Africa" to that continent. } elseif(isset($_POST['continentOfPersonalUser']) && $_POST['continentOfPersonalUser'] > $numberOfContinents){ #Here we check to ensure that the value entered is not greater than the maximum number of continents we have on our database. If it is, the value the user posted is spurious. $errors[] = 'We don\'t recognise this continent. The last continent we have on our list is South America. Please review this, or if you think this is a mistake, please contact support@churchmapped.com'; #Where the last continent in our database changes (e.g. due to the creation of a new continent), then we should change "South America" to that continent. } #This part deals with the country where the user works. Note that this is an optional field, unlike the country where the user resides. Because of this, we do not need to check if the user has posted the $_POST['countryOfWorkOfPersonalUser'] as with other variables. elseif(isset($_POST['countryOfWorkOfPersonalUser']) && !is_numeric(intval($_POST['countryOfWorkOfPersonalUser']))){ #Here we check to see whether $_POST['countryOfWorkOfPersonalUser'] is an integer. This is because country_of_place_of_work_of_user_on_churchmapped is of the type TINYINT. If it is not an integer, then it is possible the user is trying to tamper with the value. $errors[] = 'This is not a country we recognise. Please provide a country we recognise. If you believe this is an error, please contact support@churchmapped.com'; } elseif(isset($_POST['countryOfWorkOfPersonalUser']) && $_POST['countryOfWorkOfPersonalUser'] < 1){ #Here we check to see whether $_POST['countryOfWorkOfPersonalUser'] is less than 1. This is a spurious value because values begin from 1 (i.e. Afghanistan - although note that where a new country is formed and precedes Afghanistan or Afghanistan changes its name, the country corresponding to 1 will change. $errors[] = 'We don\'t recognise this country. The first country we have on our list is Afghanistan. Please review the place in which you work, or if you think this is a mistake, please contact support@churchmapped.com'; #Where the first country in our database changes (e.g. due to the creation of a new country), then we should change "Afghanistan" to that country. } elseif(isset($_POST['countryOfWorkOfPersonalUser']) && $_POST['countryOfWorkOfPersonalUser'] > $numberOfCountries){ #Here we check to see whether $_POST['countryOfWorkOfPersonalUser'] is greater than the number of countries. If it is, this indicates that perhaps the user is trying to tamper with the value of countries. $errors[] = 'We don\'t recognise this country. The last country we have on our list is Zimbabwe. Please review the place in which you work, or if you think this is a mistake, please contact support@churchmapped.com'; #Where the last country in our database changes (e.g. due to the creation of a new country), then we should change "Zimbabwe" to that country. } #This part deals with the continent where the user works. Note that this is an optional field, unlike the continent where the user resides. Because of this, we do not need to check if the user has posted the $_POST['continentOfWorkOfPersonalUser'] as we might need to do with the continent of residence of the personal user. elseif(isset($_POST['continentOfWorkOfPersonalUser']) && !is_numeric(intval($_POST['continentOfWorkOfPersonalUser']))){ #Here we check to see whether $_POST['continentOfWorkOfPersonalUser'] is an integer. This is because continent_of_place_of_work_of_churchmapped_user is of type TINYINT. $errors[] = 'This is not a continent we recognise. Please provide a continent where you work which we recognise. If you believe this is an error, please contact support@churchmapped.com'; } elseif(isset($_POST['continentOfWorkOfPersonalUser']) && $_POST['continentOfWorkOfPersonalUser'] < 1){ #Here we check to see whether $_POST['continentOfWorkOfPersonalUser'] is les than 1. This is a spurious value because values begin from 1. $errors[] = 'We don\'t recognise this continet. The first continent we have on our list is Africa. Please review this, or if you think this is a mistake, please contact support@churchmapped.com'; #Where the first continent in our database (by alphabetical order) changes (e.g. due to the creation of a new continent or the renaming of the continent), then we should change "Africa" to that continent. } elseif(isset($_POST['continentOfWorkOfPersonalUser']) && $_POST['continentOfWorkOfPersonalUser'] > $numberOfContinents){ #Here we check to see if the options value of the continents comports with the number of continents. If not, then this is an indication that the user is perhaps attempting to tamper with the field . $errors[] = 'We don\'t recognise this continent. The last continent we have on our list is South America. Please review the continent in which you work, or if you think this is a mistake, please contact support@churchmapped.com'; #Where the last continent in our database changes (e.g. due to the creation of a new continent), then we should change "South America" to that continent. } #This section deals with Address Line 1. This is a required field, so we have to check that the user has in fact posted the first line of address elseif(!isset($_POST['addressLineOneOfPersonalUser'])){ #Here we check to see if the user has submitted the first line of their address. If not, then we issue an error statement. $errors[] = 'You have not filled in the first line of your address. This is a requirement in joining the ChurchMapped platform. Please fill this in and re-submit'; } elseif(isset($_POST['addressLineOneOfPersonalUser']) && (strlen($_POST['addressLineOneOfPersonalUser']) < 1 || strlen($_POST['addressLineOneOfPersonalUser']) > 50)){ #Here we check to ensure that the address fits within the limit we have set of 50 characters. If it is more than this, something is wrong. Similarly, we check here to ensure that the length of address line one is not less than 1. It is possible in rare cases that the first line of address might be even longer than 50 characters; due to this, although we issue an error statement, we communicate to the user that if it seems there is an issue, they should contact support@churchmapped.com $errors[] = 'You have entered an address that is either too short or too long. The first line of address must be between 1 and 50 characters long (all inclusive). If, however, the first line of your address does not fit this requirement, please contact support@churchmapped.com so that we can look into this for you'; } # This section deals with Address Line 2. Note that this is *NOT* a required field. Therefore, there is no need to check first whether the user has in fact submitted this value. In other words, the only thing we will be checking here is the string length. elseif(isset($_POST['addressLineTwoOfPersonalUser']) && !empty($_POST['addressLineTwoOfPersonalUser']) && (strlen($_POST['addressLineTwoOfPersonalUser']) < 1 || strlen($_POST['addressLineTwoOfPersonalUser']) > 50)){ #Here we check to see that the address line 2, if (and I must stress, *if*) it is submitted, is between 1 and 50 characters. Like the first line of address, there is a possibility that the second line of address might in fact be genuinely longer than this constraint, so when we issue the error statement, we inform the user that they can contact support@churchmapped.com if they believe this is an error. We use the empty() method because even in the absence of any data, the form posts *everything*. Basically what we try to see is whether the second line of address has any data connected to it - if not, then we check to see the string length. $errors[] = 'You have entered an address that is either too short or too long. The second line of address must be between 1 and 50 characters long (all inclusive). If, however, the second line of your address does not fit this requirement, please contact support@churchmapped.com so that we can look into this for you.'; } # This section deals with Address Line 3. Note that this is *NOT* a required field. Therefore, there is no need to check first whether the user has in fact submitted this value. In other words, the only thing we will be checking here is the string length. elseif(isset($_POST['addressLineThreeOfPersonalUser']) && !empty($_POST['addressLineThreeOfPersonalUser']) && (strlen($_POST['addressLineThreeOfPersonalUser']) < 1 || strlen($_POST['addressLineThreeOfPersonalUser']) > 50)){ #Here we check to see that the address line 3, if (and I must stress, *if*) it is submitted, is between 1 and 50 characters. Like the first line of address, there is a possibility that the third line of address might in fact be genuinely longer than this constraint, so when we issue the error statement, we inform the user that they can contact support@churchmaped.com if they believe this is an error. We use the empty() method because even in the absence of any data, the form posts *everything*. Basically what we try to see is whether the third line of address has any data connected to it - if not, then we check to see the string length. $errors[] = 'You have entered an address that is either too short or too long. The third line of address must be between 1 and 50 characters (all inclusive). If, however, the third line of your address does not fit this requirement, please contact support@churchmapped.com so that we can look into this for you.'; } #This section deals with the City. This is a *required* field. Therefore, we need to check if the user has in fact submitted a value for city. To ensure that a user doesn't submit just whitespace or unusual characters so as to avoid providing their city, we use the preg_match() function as well to ensure that at least one alphabetical character is included in the City (because all cities have at least one alphabetical character). Having said this though, we should be sure to communicate to the user that they can contact us on support@churchmapped.com if they think this is a mistake because it might happen that a user enters non-English characters into the City field and it's registered by the preg_match() function as no alphabetical characters being used (because RegEx functions are built only with English characters in mind). The pattern we use is set to a variable called $patternForAlphabeticalOrder and the regular expression is /[a-zA-Z]+/ . elseif(!isset($_POST['cityOfPersonalUser'])){ #Here we check to see if the user has submitted the city in which they are based. If they haven't, we issue an error statement. $errors[] = 'You have not entered the city in which you are based. This is a requirement. Please revise your submission'; } elseif(isset($_POST['cityOfPersonalUser']) && (preg_match($patternForAlphabeticalOrder, $_POST['cityOfPersonalUser']) == 0 || !preg_match($patternForAlphabeticalOrder, $_POST['cityOfPersonalUser']))){ #Here we check to see if the City field contains at least one alphabetical character, to prevent spurious submissions. However, it is possible, because of the way regular expressions work and how they are tailored for the English language, that a preg_match() function returns 0 even though a legitimate character is used but it just so happens to be non-English. Whilst there is an mb_len() function, in my opinion, it is better to simply request the user to email support@churchmapped.com and we will manually add the user into the database. $errors[] = 'This city does not seem to contain any characters we require. Please revise, or if you think this is an error, please contact support@churchmapped.com so that we can look into this'; } elseif(isset($_POST['cityOfPersonalUser']) && !empty($_POST['cityOfPersonalUser']) && (strlen($_POST['cityOfPersonalUser']) < 1 || strlen($_POST['cityOfPersonalUser']) > 50)){ #Here we check to see that the city entered by the personal user is within the character limit we have set for the City field between 1 and 50 characters. In the event the city field is longer than 50 characters for some reason, we issue an error statement but state within it that if the user thinks this is an error, they should speak to us via support@churchmapped.com $errors[] = 'The name you have provided for your city has either too few or too many characters. Please do revise this, or if you think this is a mistake, please contact support@churchmapped.com so that we can look into this'; } #This section deals with Postcode. Interestingly, this is not a required field and we have not set it to be a required field. The reason for this is because some places in the world - the most famous of this being the Republic of Ireland - have no postcode. Therefore, we shouldn't require it. Therefore, there is no need to check here whether the user has submitted. The only thing we need to check for in this section is whether the postcode is within the character limit we have set of 1 and 15 characters (all inclusive) *where the user has submitted information relating to their postcode. As with the first line of address and other fields in this registration form, when we provide the error statement, we have to communicate to the user that they should contact support@churchmapped.com if they believe they are seeing this in error. elseif(isset($_POST['postcodeOfPersonalUser']) && (strlen($_POST['postcodeOfPersonalUser']) < 1 || strlen($_POST['postcodeOfPersonalUser']) > 15)){ $errors[] = 'Your postcode/zipcode seems either too short or too long. Please do revise this, or if you think this is a mistake, please contact support@churchmapped.com so that we can look into this'; } # This section deals with the terms and conditions. It is arguably the most important part, together with the privacy policy. We need to check two things. The first, whether the user has submitted (i.e. "checked") at all the Terms and Conditions. The second is whether the value of the Terms & Conditions is an integer. The value of the Terms & Conditions is an integer because this corresponds to the version/id number of the legal document in question on our database. elseif(!isset($_POST['termsAndConditionsVersionForPersonalUser'])){ #Here we check to see if the user agrees to the terms and conditions. Note that where we update the Terms & Conditions, we have to update this area as well. $errors[] = 'You have not indicated whether or not you agree with the Terms and Conditions. It is a condition of using the ChurchMapped platform that you agree to the Terms and Conditions. Please check the box to indicate you agree to the Terms & Conditions'; } elseif(isset($_POST['termsAndConditionsVersionForPersonalUser']) && !is_numeric($_POST['termsAndConditionsVersionForPersonalUser'])){ #Here we check to see if the Terms & Conditions is an integer. If not, this is an indication it is a spurious value because the value we send to the database is an integer (not actually the text of the Terms & Conditions itself!) $errors[] = 'We do not understand this value for the Terms & Conditions. Please contact support@churchmapped.com for assistance'; } #This section deals with the privacy policy. Like the Terms & Conditions, it is also arguably the most important part. We need to check two things. The first, whether the user has submitted (i.e. "checked") at all the Privacy Policy. The second is whether the value of the Privacy Policy is an integer. The value of the Privacy Policy is an integer because this corresponds to the version/id number of the legal document in question on our database. elseif(!isset($_POST['privacyPolicyVersionForPersonalUser'])){ #Here we check to see whether the user has indicated whether or not they agree to the privacy policy or not. Note that where we update the Privacy Policy, we have to update this area as well. $errors[] = 'You have not indicated whether or not you agree with our privacy policy. Please indicate your agreement in order to successfully join the ChurchMapped platform'; } elseif(isset($_POST['privacyPolicyVersionForPersonalUser']) && !is_numeric($_POST['privacyPolicyVersionForPersonalUser'])){ #Here we check to see if the Privacy Policy is an integer through the is_numeric() function. If not, this is an indication that it is a spurious value because the value we send to the database is an integer (not actually the text of the Privacy Policy itself!) $errors[] = 'We do not understand this value for the Privacy Policy. Please contact support@churchmapped.com for assistance.'; } #Once we have checked and validated all the user input, we begin the segment for the email and inputting the values into the database. if(empty($errors)){ #If there are no errors, we send an e-mail the user so that they can activate their account. However, note that the flow is different for users who opt for what we call a "protected" salutation - these include the following: echo '
Thank you for registering with ChurchMapped! We found no issues with your registration form at this stage. Please expect an email from us shortly.
'; # - His Eminence # - His Highness # - Her Highness # - Beatitude # - Fr. # - Monsignor # - Deacon # - Mother # - Sister # - Brother # - Canon # - President # - Vice President # If the user is in any of these categories, we send the mail to support@churchmapped.com with all the user's information (i.e. basically all of $_POST) and we correspond with the user before activating their profile. However, where the user does not have a salutation that falls into these categories, we send the user an activation code in the GET variables. The activation code is comprised of two variables: $m and $d. $m signifies the email used to register. It is taken by using the method bin2hex() for the email address the user used when registering. For instance, the email babatunde.onabajo@churchmapped.com gives the hexadecimal value of 6261626174756e64652e6f6e6162616a6f406368757263686d61707065642e636f6d. $d is the date the user registered with and is given by date(Y-m-d) registered. If both values are correct, that is they match what is in our database, we activate the user by setting has_churchmapped_user_confirmed_email_address to 2 (by default, it is 1). We then send another mail (the script is in activateuser.html though on a local server this is activateuser.php for IDE purposes) informing them that their email address is now confirmed. if($_POST['salutationOfPersonalUser'] == "His Eminence" || $_POST['salutationOfPersonalUser'] == "His Higness" || $_POST['salutationOfPersonalUser'] == "Her Highness" || $_POST['salutationOfPersonalUser'] == "Beatitude" || $_POST['salutationOfPersonalUser'] == "Fr." || $_POST['salutationOfPersonalUser'] == "Monsignor" || $_POST['salutationOfPersonalUser'] == "Deacon" || $_POST['salutationOfPersonalUser'] == "Mother" || $_POST['salutationOfPersonalUser'] == "Sister" || $_POST['salutationOfPersonalUser'] == "Brother" || $_POST['salutationOfPersonalUser'] == "Canon" || $_POST['salutationOfPersonalUser'] == "President" || $_POST['salutationOfPersonalUser'] == "Vice President"){ #Here we deal with the situation of where the user uses a protected salutation. #We use the mail() function to send a mail to *both* the user and the support team at ChurchMapped. Where the user uses a protected salutation, we just send an email to the user notifying them that a registration was made and that we will be in touch shortly. *However*, this mail does not activate their account in any way; we have to do that manually. This is in start contrast to the situation where a user does not use a protected salutation, wherein we send an activation code to the user. # This section uses prepared statements to insert values into the database. These are the values we insert into the database together with the type in brackets: # 1 # salutation_of_user_on_churchmapped (s) - $_POST['salutationOfPersonalUser'] # 2 # first_name_of_user_on_churchmapped (s) - $_POST['firstNameOfPersonalUser'] # 3 # middle_name_of_user_on_churchmapped (s) - $_POST['middleNameOfPersonalUser'] # 4 # surname_of_user_on_churchmapped (s) - $_POST['surnameOfPersonalUser'] # 5 # date_of_birth_of_personal_churchmapped_user (s) - $_POST['yearOfBirthOfPersonalUser'] . - . $_POST['monthOfBirthOfPersonalUser'] . - . $_POST['dayOfBirthOfPersonalUser'] (we have to concatenate the values) # 6 # sex_of_user_on_churchmapped (i) - $_POST['genderOfPersonalUser'] # 7 # handle_of_user_on_churchmapped (s) - $_POST['churchmappedHandleOfPersonalUser'] # 8 # primary_email_of_user_on_churchmapped (s) - $_POST['emailOfPersonalUser'] # 9 # password_of_user_on_churchmapped (s) - $_POST['passwordOfPersonalUser'] (don't forget to hash this!) # 10 # has_churchmapped_user_confirmed_email_address (i) - this takes a value of 1 where the user has not yet confirmed their email; otherwise, where they have confirmed it, it is 2. This is an integer. # 11 # whether_user_requires_extra_authorisation (i) - This takes two values: 1 indicates not approved and 2 indicates approved. It is used for situations where a user uses a protected salutation such as Fr. # 12 # country_of_residence_of_user_on_churchmapped (i) - $_POST['countryOfPersonalUser'] (This is the country of residence of the user. It is an integer value because that is the value we use for the stored procedure which checks the integer against the ID in the corresponding table.) # 13 # country_of_place_of_work_of_user_on_churchmapped (i) - $_POST['countryOfWorkOfPersonalUser'] (This is the country of work of the user. It is an integer value because that is the value we use for the stored procedure which checks the integer against the ID in the corresponding table). # 14 # personal_address_line_one_of_user_of_churchmapped (s) - $_POST['addressLineOneOfPersonalUser'] # 15 # personal_address_line_two_of_user_on_churchmapped (s) - $_POST['addressLineTwoOfPersonalUser'] # 16 # personal_address_line_three_of_user_on_churchmapped (s) - $_POST['addressLineThreeOfPersonalUser'] # 17 # city_of_residence_of_user_on_churchmapped (s) - $_POST['cityOfPersonalUser'] # 18 # postcode_of_residence_of_user_on_churchmapped (s) - $_POST['postcodeOfPersonalUser'] # 19 # continent_of_residence_of_churchmapped_user (i) - $_POST['continentOfPersonalUser'] (This is the continent of residence of the user. It is an integer value because that is the value we use for the stored procedure which seeks the integer against the ID in the corresponding table). # 20 # continent_of_place_of_work_of_churchmapped_user (i) - $_POST['continentOfWorkOfPersonalUser'] (This is the continent of the place where the user works. It is an integer value because that is the value we use for the stored procedure which seeks the integer against the ID in the corresponding table) # 21 # date_and_time_of_registration_of_churchmapped_user (s) - This is the date and time the user registers. This is a special field in that it is not user generated. Rather, we create it ourselves on the backend using PHP's date("Y-m-d H:i:s") function. We set the type to string (s) for the purposes of our prepared statement below. # 22 # version_of_terms_and_conditions_agreed_to_by_churchmapped_user (i) - $_POST['termsAndConditionsVersionForPersonalUser'] # 23 # version_of_privacy_policy_agreed_to_by_churchmapped_user (i) - $_POST['privacyPolicyVersionForPersonalUser'] # 24 # ip_address_at_point_of_registration (s) - This is the IP address of the user when they register. This is a special field in that it is not user generated. Rather, we obtain it by accessing the file getuserip.php, which sets the IP address to a session variable and has already been validated by us and so we can be assured it can't be used for potential SQL injection attacks. The IP address is stored in the session variable $_SESSION['sessionIPAddress']. Note that when testing this on a local server, it might not work because the local server does not have an IP address per se. # 25 # date_and_time_of_version_of_agreement_to_terms_of_conditions (s) - This is the date and time at which a user agrees to the terms and conditions. # 26 # date_and_time_of_version_of_agreement_to_privacy_policy (s) - This is the date and time of the agreement to a particular privacy policy by the user. # bind_param: sssssisssiiiisssssiisiisss $passwordhash = "YouAreTheSaltOfTheEarthACityOnAHill!!!July2021"; #This is the hash we use for the password of the ChurchMapped user. We should not change this, or where we change it, we have to reset the password for all ChurchMapped users. This is strictly confidential. $stmt = $conn->prepare("INSERT INTO churchma_USERS_ON_CHURCHMAPPED.user_details_on_churchmapped(salutation_of_user_on_churchmapped, first_name_of_user_on_churchmapped, middle_name_of_user_on_churchmapped, surname_of_user_on_churchmapped, date_of_birth_of_personal_churchmapped_user, sex_of_user_on_churchmapped, handle_of_user_on_churchmapped, primary_email_of_user_on_churchmapped, password_of_user_on_churchmapped, has_churchmapped_user_confirmed_email_address, whether_user_requires_extra_authorisation, country_of_residence_of_user_on_churchmapped, country_of_place_of_work_of_user_on_churchmapped, personal_address_line_one_of_user_of_churchmapped, personal_address_line_two_of_user_on_churchmapped, personal_address_line_three_of_user_on_churchmapped, city_of_residence_of_user_on_churchmapped, postcode_of_residence_of_user_on_churchmapped, continent_of_residence_of_churchmapped_user, continent_of_place_of_work_of_churchmapped_user, date_and_time_of_registration_of_churchmapped_user, version_of_terms_and_conditions_agreed_to_by_churchmapped_user, version_of_privacy_policy_agreed_to_by_churchmapped_user, ip_address_at_point_of_registration, date_and_time_of_version_of_agreement_to_terms_of_conditions, date_and_time_of_version_of_agreement_to_privacy_policy) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param("sssssisssiiiisssssiisiisss", $salutationofuseronchurchmapped, $firstnameofuseronchurchmapped, $middlenameofuseronchurchmapped, $surnameofuseronchurchmapped, $dateofbirthofuseronchurchmapped, $sexofuseronchurchmapped, $handleofchurchmappeduser, $primaryemailofchurchmappeduser, $passwordofchurchmappeduser, $haschurchmappeduserconfirmedemailaddress, $whetheruserrequiresextraauthorisation, $countryofresidenceofuseronchurchmapped, $countryofplaceofworkofuseronchurchmapped, $personaladdresslineoneofuserchurchmapped, $personaladdresslinetwoofuserchurchmapped, $personaladdresslinethreeofuserchurchmapped, $cityofresidenceofuseronchurchmapped, $postcodeofresidenceofuseronchurchmapped, $continentofuseronchurchmapped, $continentofworkofuseronchurchmapped, $dateandtimeofregistrationofchurchmappeduser, $termsandconditionsagreedtobychurchmappeduser, $versionofprivacypolicyagreedtobychurchmappeduser, $ipaddressatpointofregistration, $dateandtimeofversionofagreementtotermsandconditions, $dateandtimeofversionofagreementtoprivacypolicy); #Don't forget to trim all the variables to remove whitespace; with the exception of password $salutationofuseronchurchmapped = trim($_POST['salutationOfPersonalUser']); #This is the salutation of the personal user on ChurchMapped $firstnameofuseronchurchmapped = trim($_POST['firstNameOfPersonalUser']); #This is the first name of the personal user on ChurchMapped $middlenameofuseronchurchmapped = trim($_POST['middleNameOfPersonalUser']); #This is the middle name of the personal user on ChurchMapped $surnameofuseronchurchmapped = trim($_POST['surnameOfPersonalUser']); #This is the surname of the personal user on ChurchMapped $dateofbirthofuseronchurchmapped = trim($_POST['yearOfBirthOfPersonalUser']) . '-' . trim($_POST['monthOfBirthOfPersonalUser']) . '-' . trim($_POST['dayOfBirthOfPersonalUser']); #This is the date of birth of the personal user on ChurchMapped $sexofuseronchurchmapped = trim($_POST['genderOfPersonalUser']); #This is the sex of the personal user on ChurchMapped $handleofchurchmappeduser = trim($_POST['churchmappedHandleOfPersonalUser']); #This is the handle of the ChurchMapped user $primaryemailofchurchmappeduser = trim($_POST['emailOfPersonalUser']); #This is the email address of the ChurchMapped user $passwordofchurchmappeduser = md5($passwordhash . $_POST['passwordOfPersonalUser']); #This is the password of the ChurchMapped user. Remember that we don't use the trim() function for the password. We also use the variable $passwordhash for the SALT. The password is stored in the database via the md5() function. $haschurchmappeduserconfirmedemailaddress = 1; #This variable is used for whether the ChurchMapped user has activated their account by clicking the link in the email. Note that in the situation where a user uses a protected salutation, we have to manually update this value in the database to 2. $whetheruserrequiresextraauthorisation = 1; #This is used for whether the user requires extra authorisation. Where a user uses a protected salutation such as "Fr.", we set this value to 1, which prevents the user with the protected salutation from logging in. It is only after we are happy with our checks do we manually change this to 2. However, this is different for users who are not using a protected salutation (e.g. Mr.). In this case, we set the value to 2. $countryofresidenceofuseronchurchmapped = trim(intval($_POST['countryOfPersonalUser'])); #We use the method intval() to ensure once again that the value is in fact an integer. We use the trim() method to remove any whitespace $countryofplaceofworkofuseronchurchmapped = trim(intval($_POST['countryOfWorkOfPersonalUser'])); #We use the method intval() to ensure that the value is in fact an integer. We use the trim() method to remove any whitespace $personaladdresslineoneofuserchurchmapped = trim($_POST['addressLineOneOfPersonalUser']); #This is the address line one of the personal user $personaladdresslinetwoofuserchurchmapped = trim($_POST['addressLineTwoOfPersonalUser']); #This is the address line two of the personal user $personaladdresslinethreeofuserchurchmapped = trim($_POST['addressLineThreeOfPersonalUser']); #This is the address line three of the personal user $cityofresidenceofuseronchurchmapped = trim($_POST['cityOfPersonalUser']); #This is the city of residence of the user on ChurchMapped $postcodeofresidenceofuseronchurchmapped = trim($_POST['postcodeOfPersonalUser']); #This is the postcode of the user on ChurchMapped $continentofuseronchurchmapped = trim(intval($_POST['continentOfPersonalUser'])); #This is the continent of residence of the user on ChurchMapped. We use the method intval() to ensure once again that the value is in fact an integer. We use the trim() method to remove any whitespace. $continentofworkofuseronchurchmapped = trim(intval($_POST['continentOfWorkOfPersonalUser'])); #This is the continent of the place of work of the user on ChurchMapped. We use the method intval() to ensure once again that the value is in fact an integer. We use the trim() method to remove any whitespace. $dateandtimeofregistrationofchurchmappeduser = date("Y-m-d H:i:s"); #This provides the date of the registation. Note that it is not user-generated. Furthermore, we do not need to use the trim() function here because it is not user-generated. $termsandconditionsagreedtobychurchmappeduser = trim(intval($_POST['termsAndConditionsVersionForPersonalUser'])); #This is the terms and conditions agreed to by the user $versionofprivacypolicyagreedtobychurchmappeduser = trim(intval($_POST['privacyPolicyVersionForPersonalUser'])); #This is the privacy policy agreed to by the ChurchMapped user $ipaddressatpointofregistration = $_SESSION['sessionIPAddress']; #This is the IP Address of the user, stored in the session variable. $dateandtimeofversionofagreementtotermsandconditions = date("Y-m-d H:i:s"); #This is the date and time at which a user agrees to the terms and conditions $dateandtimeofversionofagreementtoprivacypolicy = date("Y-m-d H:i:s"); #This is the date and time at which a user agrees to a particular privacy policy. #We finally insert the values into the database here wit the -> execute() method. $stmt->execute(); #This line of code fianlly executes the code above # Upon registration, we send an email to the user *and* support@churchmapped.com $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam = array(); #Here we create an array of the information relating to the user with a protected salutation. Note: We do not include their password, obviously! We use the implode() function and
for it to be included in the e-mail. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $salutationofuseronchurchmapped; #This is the salutation of the user on ChurchMapped $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $firstnameofuseronchurchmapped; #This is the first name of the user on ChurchMapped $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $middlenameofuseronchurchmapped; #This is the middle name of the user on ChurchMapped $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $surnameofuseronchurchmapped; #This is the surname of the user on ChurchMapped $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $dateofbirthofuseronchurchmapped; #This is the date of birth of the user on ChurchMapped $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $sexofuseronchurchmapped; #This is the sex of the user. Note that this is a number. It should be explained in the email. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $handleofchurchmappeduser; #This is the email of the user. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $primaryemailofchurchmappeduser; #This is the primary email address of the user. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $countryofresidenceofuseronchurchmapped; #This is the country of residence of the user in question. Note that this is an integer. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] =$countryofplaceofworkofuseronchurchmapped; #This is the country of work of the user in question. Note that this is an integer. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $personaladdresslineoneofuserchurchmapped; #This is the personal address (line one) of the user in question. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $personaladdresslinetwoofuserchurchmapped; #This is the personal address (line two) of the user in question. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $personaladdresslinethreeofuserchurchmapped; #This is the personal address (line three) of the user in question. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $cityofresidenceofuseronchurchmapped; #This is the city of residence of the user in question. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $postcodeofresidenceofuseronchurchmapped; #This is the postcode of the user in question. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $continentofuseronchurchmapped; #This is the continent of the user in question. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $continentofworkofuseronchurchmapped; #This is the continent of work of the user in question. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $dateandtimeofregistrationofchurchmappeduser; #This is the date and time of registration of the user in question. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $termsandconditionsagreedtobychurchmappeduser; #This is the version of the terms and conditions agreed to by the user in question. Note that this is an integer. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $versionofprivacypolicyagreedtobychurchmappeduser; #This is the version of the privacy policy agreed to by the user in question. Note that this is an integer. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $ipaddressatpointofregistration; #This is the IP address of the user in question $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $dateandtimeofversionofagreementtotermsandconditions; #This is the date and time the user agreed to the terms and conditions. $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam[] = $dateandtimeofversionofagreementtoprivacypolicy; #This is the date and time the user agreed to the privacy policy $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam = implode("

", $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam); #Here we send an email to support@churchmapped.com # The mail() function takes the following parameters: to, subject, message, headers, parameters $toSupportTeam = "support@churchmapped.com"; $subjectRelatingToUserWithProtectedSalutation = "IMMEDIATE ATTENTION. Please verify user: A user has registered with a protected salutation. His or her name is:" . " " . $_POST['salutationOfPersonalUser'] . " " . $_POST['firstNameOfPersonalUser'] . $_POST['surnameOfPersonalUser']; $path_of_the_logo = "https://www.churchmapped.com/churchmappedlogo.png"; $dateToday = date("l jS F Y"); $type = pathinfo($path_of_the_logo, PATHINFO_EXTENSION); $contentofimage = file_get_contents($path_of_the_logo); $image64 = "data:image/" . $type . ';base64,' . base64_encode($contentofimage); $messageRelatingToUserWithProtectedSalutation = '
' . '
' . '
'. $dateToday . '

Dear ChurchMapped Team' . ',' . '' . '

' . 'A user with a protected salutation has recently registered on the platform. Protected salutations are salutations such as Fr. and His Eminence. Due to the nature of our platform, we have to perform extra checks on this user. Please contact the user at the email address provided by him/her, namely: ' . ' ' . '' . $_POST['emailOfPersonalUser'] . '

This is what they submitted in their registration form:' . $informationAboutUserWithProtectedSalutationToBeIncludedInEmailToSupportTeam . '. If you are satisfied that the user is genuine and has provided you with satisfactory evidence, you need to manually go to the database churchma_USERS_ON_CHURCHMAPPED.users_on_churchmapped and change the value of the column whether_user_requires_extra_authorisation to 2 and the value of the column has_churchmapped_user_confirmed_email_address to 2 as well. We then send another email to the user notifying them that they can now log in. This is vital. In the situation where the user has not provided evidence of themselves to a satisfactory standard, simply leave the values as they are; in extreme cases, alert the manager to identify the issue in cases where you suspect it might be due to fraud.' . '
The social network that aspires to do better ❤
' . '
See our terms and conditions here.| See our privacy policy here.| Visit ChurchMapped here.
' . 'ChurchMapped® Limited is a registered company in England and Wales. Our company number is 12329590 and our registered office is at 27 Old Gloucester Street, London, WC1N 3AX, United Kingdom. We are on the register of data fee payers courtesy of the Information Commissioner\'s Office (ICO) and our data protection registration number is ZA603587. Our VAT number is 340128834.
'; $headersToSupportTeamAboutUserWithProtectedSalutation = array(); #This array contains the headers for the email. $headersToSupportTeamAboutUserWithProtectedSalutation[] = "Content-Type: text/html; charset=utf-8"; $headersToSupportTeamAboutUserWithProtectedSalutation[] = "From: Support - ChurchMapped Team "; $headersToSupportTeamAboutUserWithProtectedSalutation = implode("\r\n", $headersToSupportTeamAboutUserWithProtectedSalutation); #This adds a \r\n to each line, which we need when sending mail. $dateTodayForEmailToUser = date("l jS F Y"); #We use this to date our emails to staff. mail($toSupportTeam, $subjectRelatingToUserWithProtectedSalutation, $messageRelatingToUserWithProtectedSalutation, $headersToSupportTeamAboutUserWithProtectedSalutation); #This finally sends the email to the ChurchMapped Support team. ### Here we send an email to the user with the protected salutation to inform them that we will be in touch shortly to determine whether they are in fact genuine. $headersToUserWithProtectedSalutation = array(); $headersToUserWithProtectedSalutation[] = "Content-Type: text/html; charset=utf-8"; $headersToUserWithProtectedSalutation[] = "From: Support - ChurchMapped Team "; $headersToUserWithProtectedSalutation[] = implode("\r\n", $headersToUserWithProtectedSalutation); #This adds a \r\n to each line, which we need when sending mail. $toUserWithProtectedSalutation = trim($_POST['emailOfPersonalUser']); #We can safely use $_POST['emailOfPersonalUser'] because we have already sanitised it and this segment of code only fires when our validation checks have been performed. $subjectForUserWithProtectedSalutation = "Thank you for registering with ChurchMapped!"; $messageForUserWithProtectedSalutation = '
' . '
' . '

' . $dateTodayForEmailToUser . '


Dear ' . trim($_POST['salutationOfPersonalUser']) . ' ' . trim($_POST['firstNameOfPersonalUser']) . ' ' . trim($_POST['surnameOfPersonalUser']) . ',' . '' . '

' . 'Thank you so much for registering on the ChurchMapped platform! We\'re delighted you would like to join the social network that truly cares. We have noticed that you use what we call a "protected" salutation, and so we need to perform extra validation checks to confirm your identity. Prior to this, you will be unable to log in to your account. Please expect another email in the upcoming few days from us here at the ChurchMapped Team and please have on hand information to prove your identity such as your passport and evidence of your position (for example, if you are a priest, a celebret will do). If you would like your information to be deleted prior to us confirming your identity, please email us expressing your request. Alternatively, accounts that are not activated within 6 months from the date of registration (all inclusive) will be automatically deleted from our systems, in line with our General Data Protection Regulation (GDPR) obligations.

Thank you so much once again!
Kind regards,
ChurchMapped Team' . '' . '
The social network that aspires to do better ❤
' . '
See our terms and conditions here.| See our privacy policy here.| Visit ChurchMapped here.
' . 'ChurchMapped® Limited is a registered company in England and Wales. Our company number is 12329590 and our registered office is at 27 Old Gloucester Street, London, WC1N 3AX, United Kingdom. We are on the register of data fee payers courtesy of the Information Commissioner\'s Office (ICO) and our data protection registration number is ZA603587. Our VAT number is 340128834.
'; mail($toUserWithProtectedSalutation, $messageForUserWithProtectedSalutation, $messageForUserWithProtectedSalutation, $headersToUserWithProtectedSalutation); #This line of code finally sends the email to the user with the protected salutation }else{ #Here we deal with the situation of where the user does not use a protected salutation. Unlike the case where a user has a protected salutation, with an "ordinary" user, we send the user an activation code in the GET variables. The activation code is comprised of two variables: $m and $d. $m signifies the email used to register. It is taken by using the method bin2hex() for the email address the user used when registering. For instance, the email babatunde.onabajo@churchmapped.com gives the hexadecimal value of 6261626174756e64652e6f6e6162616a6f406368757263686d61707065642e636f6d. $d is the date the user registered with hyphens and is given by date(Y-m-d) registered. If both values are correct, that is they match what is in our database, we activate the user by setting has_churchmapped_user_confirmed_email_address to 2 (by default, it is 1). We then send another mail (the script is in activateuser.html though on a local server this is activateuser.php for IDE purposes) informing them that their email address is now confirmed. # The advantage of using bin2hex() is that it provides only alphanumeric values, making them URL-friendly. This is in stark contrast to other methods like convert_uuencode(). #In our activation page we use the hex2bin() to convert the value taken from the URL and then check this in the database. #The activation page is over at: https://www.churchmapped.com/profiles/activateuser.html . Note that this is only used for personal profiles because for business profiles, like users on a personal account who use a protected salutation, we manually approve them ourselves. # Remember that when using information stored in GET variables, we should use prepared statements to prevent SQL injection attacks and other hacking attempts. # Remember that where a user is not using a protected salutation (e.g. "Fr."), we set whether_user_requires_extra_authorisation to 2. # This section uses prepared statements to insert values into the database. These are the values we insert into the database together with the type in brackets: # 1 # salutation_of_user_on_churchmapped (s) - $_POST['salutationOfPersonalUser'] # 2 # first_name_of_user_on_churchmapped (s) - $_POST['firstNameOfPersonalUser'] # 3 # middle_name_of_user_on_churchmapped (s) - $_POST['middleNameOfPersonalUser'] # 4 # surname_of_user_on_churchmapped (s) - $_POST['surnameOfPersonalUser'] # 5 # date_of_birth_of_personal_churchmapped_user (s) - $_POST['yearOfBirthOfPersonalUser'] . - . $_POST['monthOfBirthOfPersonalUser'] . - . $_POST['dayOfBirthOfPersonalUser'] (we have to concatenate the values) # 6 # sex_of_user_on_churchmapped (i) - $_POST['genderOfPersonalUser'] # 7 # handle_of_user_on_churchmapped (s) - $_POST['churchmappedHandleOfPersonalUser'] # 8 # primary_email_of_user_on_churchmapped (s) - $_POST['emailOfPersonalUser'] # 9 # password_of_user_on_churchmapped (s) - $_POST['passwordOfPersonalUser'] (don't forget to hash this!) # 10 # has_churchmapped_user_confirmed_email_address (i) - this takes a value of 1 where the user has not yet confirmed their email; otherwise, where they have confirmed it, it is 2. This is an integer. # 11 # whether_user_requires_extra_authorisation (i) - This takes two values: 1 indicates not approved and 2 indicates approved. It is used for situations where a user uses a protected salutation such as Fr. # 12 # country_of_residence_of_user_on_churchmapped (i) - $_POST['countryOfPersonalUser'] (This is the country of residence of the user. It is an integer value because that is the value we use for the stored procedure which checks the integer against the ID in the corresponding table.) # 13 # country_of_place_of_work_of_user_on_churchmapped (i) - $_POST['countryOfWorkOfPersonalUser'] (This is the country of work of the user. It is an integer value because that is the value we use for the stored procedure which checks the integer against the ID in the corresponding table). # 14 # personal_address_line_one_of_user_of_churchmapped (s) - $_POST['addressLineOneOfPersonalUser'] # 15 # personal_address_line_two_of_user_on_churchmapped (s) - $_POST['addressLineTwoOfPersonalUser'] # 16 # personal_address_line_three_of_user_on_churchmapped (s) - $_POST['addressLineThreeOfPersonalUser'] # 17 # city_of_residence_of_user_on_churchmapped (s) - $_POST['cityOfPersonalUser'] # 18 # postcode_of_residence_of_user_on_churchmapped (s) - $_POST['postcodeOfPersonalUser'] # 19 # continent_of_residence_of_churchmapped_user (i) - $_POST['continentOfPersonalUser'] (This is the continent of residence of the user. It is an integer value because that is the value we use for the stored procedure which seeks the integer against the ID in the corresponding table). # 20 # continent_of_place_of_work_of_churchmapped_user (i) - $_POST['continentOfWorkOfPersonalUser'] (This is the continent of the place where the user works. It is an integer value because that is the value we use for the stored procedure which seeks the integer against the ID in the corresponding table) # 21 # date_and_time_of_registration_of_churchmapped_user (s) - This is the date and time the user registers. This is a special field in that it is not user generated. Rather, we create it ourselves on the backend using PHP's date("Y-m-d H:i:s") function. We set the type to string (s) for the purposes of our prepared statement below. # 22 # version_of_terms_and_conditions_agreed_to_by_churchmapped_user (i) - $_POST['termsAndConditionsVersionForPersonalUser'] # 23 # version_of_privacy_policy_agreed_to_by_churchmapped_user (i) - $_POST['privacyPolicyVersionForPersonalUser'] # 24 # ip_address_at_point_of_registration (s) - This is the IP address of the user when they register. This is a special field in that it is not user generated. Rather, we obtain it by accessing the file getuserip.php, which sets the IP address to a session variable and has already been validated by us and so we can be assured it can't be used for potential SQL injection attacks. The IP address is stored in the session variable $_SESSION['sessionIPAddress']. Note that when testing this on a local server, it might not work because the local server does not have an IP address per se. # 25 # date_and_time_of_version_of_agreement_to_terms_of_conditions (s) - This is the date and time at which a user agrees to the terms and conditions. # 26 # date_and_time_of_version_of_agreement_to_privacy_policy (s) - This is the date and time of the agreement to a particular privacy policy by the user. # bind_param: sssssisssiiiisssssiisiisss $passwordhash = "YouAreTheSaltOfTheEarthACityOnAHill!!!July2021"; #This is the hash we use for the password of the ChurchMapped user. We should not change this, or where we change it, we have to reset the password for all ChurchMapped users. $stmt = $conn->prepare("INSERT INTO churchma_USERS_ON_CHURCHMAPPED.user_details_on_churchmapped(salutation_of_user_on_churchmapped, first_name_of_user_on_churchmapped, middle_name_of_user_on_churchmapped, surname_of_user_on_churchmapped, date_of_birth_of_personal_churchmapped_user, sex_of_user_on_churchmapped, handle_of_user_on_churchmapped, primary_email_of_user_on_churchmapped, password_of_user_on_churchmapped, has_churchmapped_user_confirmed_email_address, whether_user_requires_extra_authorisation, country_of_residence_of_user_on_churchmapped, country_of_place_of_work_of_user_on_churchmapped, personal_address_line_one_of_user_of_churchmapped, personal_address_line_two_of_user_on_churchmapped, personal_address_line_three_of_user_on_churchmapped, city_of_residence_of_user_on_churchmapped, postcode_of_residence_of_user_on_churchmapped, continent_of_residence_of_churchmapped_user, continent_of_place_of_work_of_churchmapped_user, date_and_time_of_registration_of_churchmapped_user, version_of_terms_and_conditions_agreed_to_by_churchmapped_user, version_of_privacy_policy_agreed_to_by_churchmapped_user, ip_address_at_point_of_registration, date_and_time_of_version_of_agreement_to_terms_of_conditions, date_and_time_of_version_of_agreement_to_privacy_policy) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param("sssssisssiiiisssssiisiisss", $salutationofuseronchurchmapped, $firstnameofuseronchurchmapped, $middlenameofuseronchurchmapped, $surnameofuseronchurchmapped, $dateofbirthofuseronchurchmapped, $sexofuseronchurchmapped, $handleofchurchmappeduser, $primaryemailofchurchmappeduser, $passwordofchurchmappeduser, $haschurchmappeduserconfirmedemailaddress, $whetheruserrequiresextraauthorisation, $countryofresidenceofuseronchurchmapped, $countryofplaceofworkofuseronchurchmapped, $personaladdresslineoneofuserchurchmapped, $personaladdresslinetwoofuserchurchmapped, $personaladdresslinethreeofuserchurchmapped, $cityofresidenceofuseronchurchmapped, $postcodeofresidenceofuseronchurchmapped, $continentofuseronchurchmapped, $continentofworkofuseronchurchmapped, $dateandtimeofregistrationofchurchmappeduser, $termsandconditionsagreedtobychurchmappeduser, $versionofprivacypolicyagreedtobychurchmappeduser, $ipaddressatpointofregistration, $dateandtimeofversionofagreementtotermsandconditions, $dateandtimeofversionofagreementtoprivacypolicy); #Don't forget to trim all the variables to remove whitespace; with the exception of password $salutationofuseronchurchmapped = trim($_POST['salutationOfPersonalUser']); #This is the salutation of the personal user on ChurchMapped $firstnameofuseronchurchmapped = trim($_POST['firstNameOfPersonalUser']); #This is the first name of the personal user on ChurchMapped $middlenameofuseronchurchmapped = trim($_POST['middleNameOfPersonalUser']); #This is the middle name of the personal user on ChurchMapped $surnameofuseronchurchmapped = trim($_POST['surnameOfPersonalUser']); #This is the surname of the personal user on ChurchMapped $dateofbirthofuseronchurchmapped = trim($_POST['yearOfBirthOfPersonalUser']) . '-' . trim($_POST['monthOfBirthOfPersonalUser']) . '-' . trim($_POST['dayOfBirthOfPersonalUser']); #This is the date of birth of the personal user on ChurchMapped $sexofuseronchurchmapped = trim($_POST['genderOfPersonalUser']); #This is the sex of the personal user on ChurchMapped $handleofchurchmappeduser = trim($_POST['churchmappedHandleOfPersonalUser']); #This is the handle of the ChurchMapped user $primaryemailofchurchmappeduser = trim($_POST['emailOfPersonalUser']); #This is the email address of the ChurchMapped user $passwordofchurchmappeduser = md5($passwordhash . $_POST['passwordOfPersonalUser']); #This is the password of the ChurchMapped user. Remember that we don't use the trim() function for the password. We also use the variable $passwordhash for the SALT. The password is stored in the database via the md5() function. $haschurchmappeduserconfirmedemailaddress = 1; #This variable is used for whether the ChurchMapped user has activated their account by clicking the link in the email. Note that in the situation where a user uses a protected salutation, we have to manually update this value in the database to 2. $whetheruserrequiresextraauthorisation = 2; #This is used for whether the user requires extra authorisation. Where a user uses a protected salutation such as "Fr.", we set this value to 1, which prevents the user with the protected salutation from logging in. It is only after we are happy with our checks do we manually change this to 2. However, this is different for users who are not using a protected salutation (e.g. Mr.). In this case, we set the value to 2. $countryofresidenceofuseronchurchmapped = trim(intval($_POST['countryOfPersonalUser'])); #We use the method intval() to ensure once again that the value is in fact an integer. We use the trim() method to remove any whitespace $countryofplaceofworkofuseronchurchmapped = trim(intval($_POST['countryOfWorkOfPersonalUser'])); #We use the method intval() to ensure that the value is in fact an integer. We use the trim() method to remove any whitespace $personaladdresslineoneofuserchurchmapped = trim($_POST['addressLineOneOfPersonalUser']); #This is the address line one of the personal user $personaladdresslinetwoofuserchurchmapped = trim($_POST['addressLineTwoOfPersonalUser']); #This is the address line two of the personal user $personaladdresslinethreeofuserchurchmapped = trim($_POST['addressLineThreeOfPersonalUser']); #This is the address line three of the personal user $cityofresidenceofuseronchurchmapped = trim($_POST['cityOfPersonalUser']); #This is the city of residence of the user on ChurchMapped $postcodeofresidenceofuseronchurchmapped = trim($_POST['postcodeOfPersonalUser']); #This is the postcode of the user on ChurchMapped $continentofuseronchurchmapped = trim(intval($_POST['continentOfPersonalUser'])); #This is the continent of residence of the user on ChurchMapped. We use the method intval() to ensure once again that the value is in fact an integer. We use the trim() method to remove any whitespace. $continentofworkofuseronchurchmapped = trim(intval($_POST['continentOfWorkOfPersonalUser'])); #This is the continent of the place of work of the user on ChurchMapped. We use the method intval() to ensure once again that the value is in fact an integer. We use the trim() method to remove any whitespace. $dateandtimeofregistrationofchurchmappeduser = date("Y-m-d H:i:s"); #This provides the date of the registation. Note that it is not user-generated. Furthermore, we do not need to use the trim() function here because it is not user-generated. $termsandconditionsagreedtobychurchmappeduser = trim(intval($_POST['termsAndConditionsVersionForPersonalUser'])); #This is the terms and conditions agreed to by the user $versionofprivacypolicyagreedtobychurchmappeduser = trim(intval($_POST['privacyPolicyVersionForPersonalUser'])); #This is the privacy policy agreed to by the ChurchMapped user $ipaddressatpointofregistration = $_SESSION['sessionIPAddress']; #This is the IP Address of the user, stored in the session variable. $dateandtimeofversionofagreementtotermsandconditions = date("Y-m-d H:i:s"); #This is the date and time at which a user agrees to the terms and conditions $dateandtimeofversionofagreementtoprivacypolicy = date("Y-m-d H:i:s"); #This is the date and time at which a user agrees to a particular privacy policy. #We finally insert the values into the database here wit the -> execute() method. $stmt->execute(); #This line of code finally executes the code above #Here we send the activation email to the user. There is no need to send an additional mail to the ChurchMapped Support team, in contrast to users using a protected salutation or for business users. However, we should secretly send a mail to joinus@churchmapped.com each time 1) attempts to register (i.e. register but have not activated their account yet) 2) successfully registers upon activating their email address. #Remember that: Unlike the case where a user has a protected salutation, with an "ordinary" user, we send the user an activation code in the GET variables. The activation code is comprised of two variables: $m and $d. $m signifies the email used to register. It is taken by using the method bin2hex() for the email address the user used when registering. For instance, the email babatunde.onabajo@churchmapped.com gives the hexadecimal value of 6261626174756e64652e6f6e6162616a6f406368757263686d61707065642e636f6d. $d is the date the user registered without any hyphens and is given by date(Ymd) registered. If both values are correct, that is they match what is in our database, we activate the user by setting has_churchmapped_user_confirmed_email_address to 2 (by default, it is 1). We then send another mail (the script is in activateuser.html though on a local server this is activateuser.php for IDE purposes) informing them that their email address is now confirmed. #Note that we do not have to do further input validation checks here because if we have reached this stage of our code, the input is valid. # The mail() function takes the following parameters: to, subject, message, headers, parameters $headersToUserWithoutProtectedSalutation = array(); $m = bin2hex($_POST['emailOfPersonalUser']); #The variable $m converts the email of the personal user to hexadecimal format. $d = bin2hex((date("Y-m-d"))); #The variable $d converts the date of today (which is the proxy for the date the user registered and the date the email is sent) to hexadecimal format. This will be used by the file activateuser.php (local)/activateuser.html (production) to find where in the database the user registered and on what day they did. Because this can only point to one user (i.e. email account and date they registered), we can safely activate the user's account. $emailOfUserWithoutProtectedSalutation = $_POST['emailOfPersonalUser']; $subjectOfEmailToUserWithoutProtectedSalutation = "Thank you for joining the ChurchMapped social network! Please read below to activate your account"; $path_of_the_logo = "https://www.churchmapped.com/churchmappedlogo.png"; $type = pathinfo($path_of_the_logo, PATHINFO_EXTENSION); $contentofimage = file_get_contents($path_of_the_logo); $image64 = "data:image/" . $type . ';base64,' . base64_encode($contentofimage); $messageInEmailForUserWithoutProtectedSalutation = '
' . '
' . '
'. '
Dear ' . trim($_POST['salutationOfPersonalUser']) . ' ' . trim($_POST['firstNameOfPersonalUser']) . ' ' . trim($_POST['surnameOfPersonalUser']) . ',' . '' . '

' . 'Thank you so much for registering on the ChurchMapped platform! We\'re delighted you would like to join the social network that truly cares. In order to join, please activate your account by clicking the following link: ' . 'https://www.churchmapped.com/profiles/activateuser.html?m=' . $m. '&d=' . $d . '

We\'re looking forward to seeing you. Thank you so much once again!
Kind regards,
ChurchMapped Team' . '' . '
The social network that aspires to do better ❤
' . '
See our terms and conditions here.| See our privacy policy here.| Visit ChurchMapped here.
' . 'ChurchMapped® Limited is a registered company in England and Wales. Our company number is 12329590 and our registered office is at 27 Old Gloucester Street, London, WC1N 3AX, United Kingdom. We are on the register of data fee payers courtesy of the Information Commissioner\'s Office (ICO) and our data protection registration number is ZA603587. Our VAT number is 340128834.
'; $headersToUserWithoutProtectedSalutation[] = "Content-Type: text/html; charset=utf-8"; $headersToUserWithoutProtectedSalutation[] = "From: Support - ChurchMapped Team "; $headersToUserWithoutProtectedSalutation = implode("\r\n", $headersToUserWithoutProtectedSalutation); #This adds a \r\n to each line, which we need when sending mail. mail($emailOfUserWithoutProtectedSalutation, $subjectOfEmailToUserWithoutProtectedSalutation, $messageInEmailForUserWithoutProtectedSalutation , $headersToUserWithoutProtectedSalutation); #This finally sends an e-mail to the user with their ID code. #Here we send a mail to joinus@churchmapped.com, which we can use for data collection purposes. $headersToJoinUsAtChurchMapped = array(); $emailToJoinUsAtChurchMapped = "joinus@churchmapped.com"; $subjectOfEmailToJoinUsAtChurchMapped = "The following user has registered an account on ChurchMapped.com:" . " " . trim($_POST['salutationOfPersonalUser']) . " " . trim($_POST['firstNameOfPersonalUser']) . " " . trim($_POST['surnameOfPersonalUser']); $messageToJoinUsAtChurchMapped = '
' . '
' . '
'. '
Dear ChurchMapped Team' . ',' . '
The following user has registered an account at on our platform, but has not yet activated their account:' . '
' . '
' . '' . '' . '' . 'When the user activates their account, a different email will be sent. This is an automated email that is being sent for data collection purposes.' . '

' . '

Kind regards,
ChurchMapped Team (Automated)' . '' . '
The social network that aspires to do better ❤
' . '
See our terms and conditions here.| See our privacy policy here.| Visit ChurchMapped here.
' . 'ChurchMapped® Limited is a registered company in England and Wales. Our company number is 12329590 and our registered office is at 27 Old Gloucester Street, London, WC1N 3AX, United Kingdom. We are on the register of data fee payers courtesy of the Information Commissioner\'s Office (ICO) and our data protection registration number is ZA603587. Our VAT number is 340128834.
'; $headersToJoinUsAtChurchMapped[] = "Content-Type: text/html; charset=utf-8"; $headersToJoinUsAtChurchMapped[] = "From: Support - ChurchMapped Team "; $headersToJoinUsAtChurchMapped = implode("\r\n", $headersToJoinUsAtChurchMapped); #This adds a \r\n to each line, which we need when sending mail. mail($emailToJoinUsAtChurchMapped, $subjectOfEmailToJoinUsAtChurchMapped, $messageToJoinUsAtChurchMapped, $headersToJoinUsAtChurchMapped); #This line of code finally sends an email to joinus@churchmapped.com } #This ends the segment of the if(){} statement where there are no errors found in the registration form. }else{ #If there are errors we publish them here to inform the user. echo "
There was an issue with the information you entered into the registration form:
"; foreach($errors as $particularerror){ #The foreach() loop basically displays all the errors. echo '
' . $particularerror . '

'; } } } echo ''; #Here we echo the JavaScript files that we need. echo ''; echo ''; ?>