AutoPulse v 1.0.1
 
Loading...
Searching...
No Matches
C:/Users/ivans/OneDrive/Документы/ZWA/sem/process-register.php File Reference

This script provides validation of user registration form inputs, saving new user data to the database in case of successful validation and starting a session for the new user. More...

Functions

 terminateRegWithError ($errorParam)
 
if(isset( $error) &&$error==="db_access_failed") validateInput ($pattern, $input)
 < Starts a new session or resumes the existing session.
 

Variables

 $user_type = $_POST['user_type'] ?? ''
 Type of user (e.g., 'private' or 'company').
 
 $first_name = $_POST['first_name'] ?? ''
 First name of the user.
 
 $last_name = $_POST['last_name'] ?? ''
 Last name of the user.
 
 $company_name = $_POST['company_name'] ?? ''
 Company name, if applicable.
 
 $email = $_POST['email'] ?? ''
 User's email address.
 
 $password = $_POST['password'] ?? ''
 Password provided by the user.
 
 $confirm_password = $_POST['confirm_password'] ?? ''
 Confirmation of the password.
 
 $patterns
 
 $isFormValid = true
 Flag to indicate whether the form input is valid.
 
if(! $isFormValid) try
 
if( $stmt->fetch()) catch(PDOException $e) $hashed_password = password_hash($password, PASSWORD_BCRYPT)
 Hashes the password securely.
 
 $_SESSION ["user_id"] = $pdo->lastInsertId()
 Stores the last inserted user ID in the session.
 
 $pdo = null
 < Regenerates the session ID to prevent session fixation attacks.
 
 exit
 < Redirects to the main page upon successful registration.
 

Detailed Description

This script provides validation of user registration form inputs, saving new user data to the database in case of successful validation and starting a session for the new user.

Terminates and redirects back to the form page with error context parameter and all the user inputs except passwords as parameters of the redirecting GET request in case of error of data validation or database communication.

Function Documentation

◆ terminateRegWithError()

terminateRegWithError ( $errorParam)

Redirects to the editdata page with the specified error parameter and current user inputs except passwords, and terminates the script.

Parameters
string$errorParamThe error parameter to be appended to the URL.

< Stores POST data.

< Sets the error parameter to true.

< Removes sensitive data from POST data.

< Builds a query string from POST data.

< Redirects to the registration page with the error parameter.

< Terminates script execution.

Checks if there was a database access error. If so, terminates the operation with an appropriate error parameter.

◆ validateInput()

if(isset($error) && $error==="db_access_failed") validateInput ( $pattern,
$input )

< Starts a new session or resumes the existing session.

Includes the database connection file. Validates input against a specified regular expression pattern.

Parameters
string$patternThe regular expression pattern.
string$inputThe input string to validate.
Returns
bool Returns true if the input matches the pattern, false otherwise.

If any form validation fails, terminates the registration process with an error.

Variable Documentation

◆ $_SESSION

$_SESSION["user_id"] = $pdo->lastInsertId()

Stores the last inserted user ID in the session.

◆ $company_name

$company_name = $_POST['company_name'] ?? ''

Company name, if applicable.

◆ $confirm_password

$confirm_password = $_POST['confirm_password'] ?? ''

Confirmation of the password.

◆ $email

$email = $_POST['email'] ?? ''

User's email address.

◆ $first_name

$first_name = $_POST['first_name'] ?? ''

First name of the user.

◆ $hashed_password

if($stmt->fetch()) catch (PDOException $e) $hashed_password = password_hash($password, PASSWORD_BCRYPT)

Hashes the password securely.

◆ $isFormValid

$isFormValid = true

Flag to indicate whether the form input is valid.

◆ $last_name

$last_name = $_POST['last_name'] ?? ''

Last name of the user.

◆ $password

$password = $_POST['password'] ?? ''

Password provided by the user.

◆ $patterns

$patterns
Initial value:
= [
'first_name' => '/^[a-zA-ZčČřŘžŽáÁíÍéÉěĚýÝůŮúÚóÓďĎťŤňŇ.\-]{2,20}$/',
'last_name' => '/^[a-zA-ZčČřŘžŽáÁíÍéÉěĚýÝůŮúÚóÓďĎťŤňŇ.\-]{2,20}$/',
'company_name' => '/^[a-zA-ZčČřŘžŽáÁíÍéÉěĚýÝůŮúÚóÓďĎťŤňŇ.\- ]{2,20}$/',
'email' => '/^[a-z0-9._]+@[a-z0-9.]+\.[a-z0-9]{2,8}$/',
'password' => '/^(?=.*[0-9])(?=.*[!@#$%^&*-_])[a-zA-Z0-9!@#$%^&*-_]{8,32}$/'
]

◆ $pdo

$pdo = null

< Regenerates the session ID to prevent session fixation attacks.

Closes the database connection.

◆ $user_type

$user_type = $_POST['user_type'] ?? ''

Type of user (e.g., 'private' or 'company').

◆ exit

exit

< Redirects to the main page upon successful registration.

◆ try

try
Initial value:
{
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = :email")
if(! $user) catch(PDOException $e) $pdo
Definition myprofile.php:59
if(! $userExists) $stmt
Definition process-accountDelete.php:48