Contactos:
+351 965 296 475
Sede:
Siga-nos!
LinkedIn
TripAdvisor
Twitter / X
Youtube
Transporte premium sob medida para todas as exigências.
_________________________________


connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// For the CAPTCHA, generate it if not already set in session
if (!isset($_SESSION['captcha'])) {
$captcha = substr(str_shuffle("ABCDEFGHJKLMNPQRSTUVWXYZ23456789"), 0, 6);
$_SESSION['captcha'] = $captcha;
}
// Initialize an array to collect all errors
$errors = [];
// Email check logic
if (isset($_GET['email'])) {
$email = $conn->real_escape_string($_GET['email']);
$stmt = $conn->prepare("SELECT email FROM DRIVERS WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
echo ($stmt->num_rows > 0) ? "This email is already registered." : "This email is available.";
$stmt->close();
exit;
}
// Username check logic
if (isset($_GET['username'])) {
$username = $conn->real_escape_string($_GET['username']);
$result = $conn->query("SELECT * FROM DRIVERS WHERE username='$username'");
echo ($result->num_rows > 0) ? "Username already taken" : "Username available";
exit;
}
// Form submission logic
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$first_name = $conn->real_escape_string($_POST['first_name']);
$surname = $conn->real_escape_string($_POST['surname']);
$username = $conn->real_escape_string($_POST['username']);
$birth_date = $_POST['birth_date'];
$nationality = $conn->real_escape_string($_POST['nationality']);
$email = $conn->real_escape_string($_POST['email']);
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$terms_accepted = isset($_POST['terms']) ? 1 : 0;
// Check if the names are in the correct format
if (!preg_match("/^[A-Za-z]{1,30}$/", $first_name)) {
$errors[] = "First name should only contain letters and be up to 30 characters.";
}
if (!preg_match("/^[A-Za-z]{1,30}$/", $surname)) {
$errors[] = "Surname should only contain letters and be up to 30 characters.";
}
// Check if the email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "Email is not valid.";
}
// Validate captcha
if ($_POST['captcha'] !== $_SESSION['captcha']) {
$errors[] = "Captcha does not match!";
}
// Check if emails match
if ($_POST['email'] !== $_POST['confirm_email']) {
$errors[] = "Emails do not match!";
}
// Check if passwords match
if ($_POST['password'] !== $_POST['confirm_password']) {
$errors[] = "Passwords do not match!";
}
// Check if terms are accepted
if (!$terms_accepted) {
$errors[] = "You must accept the terms!";
}
// Check if email is already taken
$check_email = $conn->prepare("SELECT email FROM DRIVERS WHERE email = ?");
$check_email->bind_param("s", $email);
$check_email->execute();
$check_email->store_result();
if ($check_email->num_rows > 0) {
$errors[] = "Error: This email is already registered. Please use another one.";
}
// If there are no errors, proceed to insert data
if (empty($errors)) {
$stmt = $conn->prepare("INSERT INTO DRIVERS (first_name, surname, username, birth_date, nationality, email, password_hash, terms_accepted) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssssi", $first_name, $surname, $username, $birth_date, $nationality, $email, $password, $terms_accepted);
if ($stmt->execute()) {
$errors[] = "Registration successful!";
} else {
$errors[] = "SQL Error: " . $stmt->error;
}
$stmt->close();
}
$check_email->close();
$conn->close();
}
?>
Register
$error";
}
}
?>
connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// For the CAPTCHA, generate it if not already set in session
if (!isset($_SESSION['captcha'])) {
$captcha = substr(str_shuffle("ABCDEFGHJKLMNPQRSTUVWXYZ23456789"), 0, 6);
$_SESSION['captcha'] = $captcha;
}
// Initialize an array to collect all errors
$errors = [];
// Email check logic
if (isset($_GET['email'])) {
$email = $conn->real_escape_string($_GET['email']);
$stmt = $conn->prepare("SELECT email FROM DRIVERS WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
echo ($stmt->num_rows > 0) ? "This email is already registered." : "This email is available.";
$stmt->close();
exit;
}
// Username check logic
if (isset($_GET['username'])) {
$username = $conn->real_escape_string($_GET['username']);
$result = $conn->query("SELECT * FROM DRIVERS WHERE username='$username'");
echo ($result->num_rows > 0) ? "Username already taken" : "Username available";
exit;
}
// Form submission logic
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$first_name = $conn->real_escape_string($_POST['first_name']);
$surname = $conn->real_escape_string($_POST['surname']);
$username = $conn->real_escape_string($_POST['username']);
$birth_date = $_POST['birth_date'];
$nationality = $conn->real_escape_string($_POST['nationality']);
$email = $conn->real_escape_string($_POST['email']);
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$terms_accepted = isset($_POST['terms']) ? 1 : 0;
// Check if the names are in the correct format
if (!preg_match("/^[A-Za-z]{1,30}$/", $first_name)) {
$errors[] = "First name should only contain letters and be up to 30 characters.";
}
if (!preg_match("/^[A-Za-z]{1,30}$/", $surname)) {
$errors[] = "Surname should only contain letters and be up to 30 characters.";
}
// Check if the email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "Email is not valid.";
}
// Validate captcha
if ($_POST['captcha'] !== $_SESSION['captcha']) {
$errors[] = "Captcha does not match!";
}
// Check if emails match
if ($_POST['email'] !== $_POST['confirm_email']) {
$errors[] = "Emails do not match!";
}
// Check if passwords match
if ($_POST['password'] !== $_POST['confirm_password']) {
$errors[] = "Passwords do not match!";
}
// Check if terms are accepted
if (!$terms_accepted) {
$errors[] = "You must accept the terms!";
}
// Check if email is already taken
$check_email = $conn->prepare("SELECT email FROM DRIVERS WHERE email = ?");
$check_email->bind_param("s", $email);
$check_email->execute();
$check_email->store_result();
if ($check_email->num_rows > 0) {
$errors[] = "Error: This email is already registered. Please use another one.";
}
// If there are no errors, proceed to insert data
if (empty($errors)) {
$stmt = $conn->prepare("INSERT INTO DRIVERS (first_name, surname, username, birth_date, nationality, email, password_hash, terms_accepted) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssssi", $first_name, $surname, $username, $birth_date, $nationality, $email, $password, $terms_accepted);
if ($stmt->execute()) {
$errors[] = "Registration successful!";
} else {
$errors[] = "SQL Error: " . $stmt->error;
}
$stmt->close();
}
$check_email->close();
$conn->close();
}
?>
Register
connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// For the CAPTCHA, generate it if not already set in session
if (!isset($_SESSION['captcha'])) {
$captcha = substr(str_shuffle("ABCDEFGHJKLMNPQRSTUVWXYZ23456789"), 0, 6);
$_SESSION['captcha'] = $captcha;
}
// Initialize an array to collect all errors
$errors = [];
// Email check logic
if (isset($_GET['email'])) {
$email = $conn->real_escape_string($_GET['email']);
$stmt = $conn->prepare("SELECT email FROM DRIVERS WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
echo ($stmt->num_rows > 0) ? "Invalid email" : "Ok!";
$stmt->close();
exit;
}
// Username check logic
if (isset($_GET['username'])) {
$username = $conn->real_escape_string($_GET['username']);
$result = $conn->query("SELECT * FROM DRIVERS WHERE username='$username'");
echo ($result->num_rows > 0) ? "Invalid name" : "Ok!";
exit;
}
// Form submission logic
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$first_name = $conn->real_escape_string($_POST['first_name']);
$surname = $conn->real_escape_string($_POST['surname']);
$username = $conn->real_escape_string($_POST['username']);
$birth_date = $_POST['birth_date'];
$nationality = $conn->real_escape_string($_POST['nationality']);
$email = $conn->real_escape_string($_POST['email']);
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$terms_accepted = isset($_POST['terms']) ? 1 : 0;
// Check if the names are in the correct format
if (!preg_match("/^[A-Za-z]{1,30}$/", $first_name)) {
$errors[] = "First name should only contain letters and be up to 30 characters.";
}
if (!preg_match("/^[A-Za-z]{1,30}$/", $surname)) {
$errors[] = "Surname should only contain letters and be up to 30 characters.";
}
// Check if the email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "Email is not valid.";
}
// Validate captcha
if ($_POST['captcha'] !== $_SESSION['captcha']) {
$errors[] = "Captcha does not match!";
}
// Check if emails match
if ($_POST['email'] !== $_POST['confirm_email']) {
$errors[] = "Emails do not match!";
}
// Check if passwords match
if ($_POST['password'] !== $_POST['confirm_password']) {
$errors[] = "Passwords do not match!";
}
// Check if terms are accepted
if (!$terms_accepted) {
$errors[] = "You must accept the terms!";
}
// Check if email is already taken
$check_email = $conn->prepare("SELECT email FROM DRIVERS WHERE email = ?");
$check_email->bind_param("s", $email);
$check_email->execute();
$check_email->store_result();
if ($check_email->num_rows > 0) {
$errors[] = "Error: This email is already registered. Please use another one.";
}
// If there are no errors, proceed to insert data
if (empty($errors)) {
$stmt = $conn->prepare("INSERT INTO DRIVERS (first_name, surname, username, birth_date, nationality, email, password_hash, terms_accepted) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssssi", $first_name, $surname, $username, $birth_date, $nationality, $email, $password, $terms_accepted);
if ($stmt->execute()) {
$errors[] = "Registration successful!";
} else {
$errors[] = "SQL Error: " . $stmt->error;
}
$stmt->close();
}
$check_email->close();
$conn->close();
}
?>
Register
connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// For the CAPTCHA, generate it if not already set in session
if (!isset($_SESSION['captcha'])) {
$captcha = substr(str_shuffle("ABCDEFGHJKLMNPQRSTUVWXYZ23456789"), 0, 6);
$_SESSION['captcha'] = $captcha;
}
// Initialize an array to collect all errors
$errors = [];
// Email check logic
if (isset($_GET['email'])) {
$email = $conn->real_escape_string($_GET['email']);
$stmt = $conn->prepare("SELECT email FROM DRIVERS WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
echo ($stmt->num_rows > 0) ? "This email is already registered." : "This email is available.";
$stmt->close();
exit;
}
// Username check logic
if (isset($_GET['username'])) {
$username = $conn->real_escape_string($_GET['username']);
$result = $conn->query("SELECT * FROM DRIVERS WHERE username='$username'");
echo ($result->num_rows > 0) ? "Username already taken" : "Username available";
exit;
}
// CAPTCHA refresh logic (if the CAPTCHA refresh button is pressed)
if (isset($_POST['refresh_captcha'])) {
$new_captcha = substr(str_shuffle("ABCDEFGHJKLMNPQRSTUVWXYZ23456789"), 0, 6);
$_SESSION['captcha'] = $new_captcha;
echo $new_captcha; // Output the new captcha
exit();
}
// Function for generating a new numeric-only activation code
function generateActivationCode() {
return str_pad(random_int(1000000000, 9999999999), 10, '0', STR_PAD_LEFT); // Generates a 10-digit numeric code
}
// Form submission logic
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Collect and escape form data
$first_name = $conn->real_escape_string($_POST['first_name']);
$surname = $conn->real_escape_string($_POST['surname']);
$username = $conn->real_escape_string($_POST['username']);
$birth_date = $_POST['birth_date'];
$nationality = $conn->real_escape_string($_POST['nationality']);
$email = $conn->real_escape_string($_POST['email']);
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$terms_accepted = isset($_POST['terms']) ? 1 : 0;
$phone_number = $conn->real_escape_string($_POST['phone_number']); // New phone number input
$country_code = $conn->real_escape_string($_POST['country_code']); // Country code input
// Check if the names are in the correct format
if (!preg_match("/^[A-Za-z]{1,30}$/", $first_name)) {
$errors[] = "First name should only contain letters and be up to 30 characters.";
}
if (!preg_match("/^[A-Za-z]{1,30}$/", $surname)) {
$errors[] = "Surname should only contain letters and be up to 30 characters.";
}
// Check if the email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "Email is not valid.";
}
// Validate captcha
if ($_POST['captcha'] !== $_SESSION['captcha']) {
$errors[] = "Captcha does not match!";
}
// Check if emails match
if ($_POST['email'] !== $_POST['confirm_email']) {
$errors[] = "Emails do not match!";
}
// Check if passwords match
if ($_POST['password'] !== $_POST['confirm_password']) {
$errors[] = "Passwords do not match!";
}
// Check if terms are accepted
if (!$terms_accepted) {
$errors[] = "You must accept the terms!";
}
// Validate phone number format (must contain at least 4 digits)
if (!preg_match('/^\d{1,4}[\s\(\)-]?\d{1,4}[\s\(\)-]?\d{1,4}[\s\(\)-]?\d{1,4}$/', $phone_number)) {
$errors[] = "Phone number must contain at least 4 digits.";
}
// Ensure that the country_code is provided if phone number is given
if (!empty($phone_number) && empty($country_code)) {
$errors[] = "Country code is required if phone number is provided.";
}
// Check if email is already taken
$check_email = $conn->prepare("SELECT email FROM DRIVERS WHERE email = ?");
$check_email->bind_param("s", $email);
$check_email->execute();
$check_email->store_result();
if ($check_email->num_rows > 0) {
$errors[] = "Error: This email is already registered. Please use another one.";
}
// Check if the birth date is valid (between 18 and 100 years old)
$dob = new DateTime($birth_date);
$now = new DateTime();
$age = $now->diff($dob)->y;
if ($age < 18 || $age > 100) {
$errors[] = "Age must be between 18 and 100 years old.";
}
// If there are no errors, proceed to insert data
if (empty($errors)) {
// Generate numeric-only activation code
$activationCode = generateActivationCode(); // Use new code generation method
echo "Generated Activation Code: " . $activationCode . "
"; // Debugging output
// Insert into the database
$stmt = $conn->prepare("INSERT INTO DRIVERS (first_name, surname, username, birth_date, nationality, email, password_hash, terms_accepted, phone_number, country_code, active, activation_code) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$active = 0; // Default value for active
$stmt->bind_param("sssssssssssi", $first_name, $surname, $username, $birth_date, $nationality, $email, $password, $terms_accepted, $phone_number, $country_code, $active, $activationCode);
if ($stmt->execute()) {
// Prepare the subject and the formatted message
$subject = "Activation Driver";
$activationUrl = "https://clicktrip.pt/Logger/Driver/activate.php?code=$activationCode";
// Formatting the message to match the structure you requested
$message = "First Name: $first_name ;;;\n";
$message .= "Email: $email ;;;\n";
$message .= "Activation link: $activationUrl ;;;\n";
// Set the 'To' address to activation@clicktrip.pt (without CC)
$headers = "From: activation@clicktrip.pt\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
// Send the email to activation@clicktrip.pt without CC
if (mail("activation@clicktrip.pt", $subject, $message, $headers)) {
// Registration successful, email sent
$_SESSION['captcha'] = substr(str_shuffle("ABCDEFGHJKLMNPQRSTUVWXYZ23456789"), 0, 6);
header("Location: Register_sucess.php"); // Redirect to success page
exit();
} else {
// Error sending email
$_SESSION['captcha'] = substr(str_shuffle("ABCDEFGHJKLMNPQRSTUVWXYZ23456789"), 0, 6);
header("Location: Register_error.php"); // Redirect on error
exit();
}
} else {
// Registration failed
$_SESSION['captcha'] = substr(str_shuffle("ABCDEFGHJKLMNPQRSTUVWXYZ23456789"), 0, 6);
header("Location: Register_error.php"); // Redirect on error
exit();
}
$stmt->close();
}
$check_email->close();
$conn->close();
// Store errors in session
$_SESSION['errors'] = $errors;
$_SESSION['error_time'] = time();
}
// Check if errors exist and if the timestamp is older than 10 seconds
if (isset($_SESSION['errors']) && isset($_SESSION['error_time'])) {
$timeElapsed = time() - $_SESSION['error_time']; // Calculate time since error occurred
// If more than 10 seconds have passed, delete errors
if ($timeElapsed > 10) {
unset($_SESSION['errors']);
unset($_SESSION['error_time']);
}
}
// If errors exist, pass them to JavaScript
if (isset($_SESSION['errors'])) {
$errors = $_SESSION['errors'];
unset($_SESSION['errors']); // Optionally clear the errors after displaying
} else {
$errors = []; // No errors
}
?>
Register