���ѧۧݧ�ӧ�� �ާ֧ߧ֧էا֧� - ���֧էѧܧ�ڧ��ӧѧ�� - /home/rickpfrv/pookie.au/subscribe.php
���ѧ٧ѧ�
<?php header('Content-Type: application/json'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST'); header('Access-Control-Allow-Headers: Content-Type'); if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit; } // load config for name variations $config = require __DIR__ . '/config.php'; $names = $config['names']; $name = $names[array_rand($names)]; if ($_SERVER['REQUEST_METHOD'] !== 'POST') { http_response_code(405); echo json_encode(['error' => $name . ' only accepts POST requests, bestie']); exit; } $input = json_decode(file_get_contents('php://input'), true); if (!$input || empty($input['email'])) { http_response_code(400); echo json_encode(['error' => $name . ' needs your email']); exit; } $email = filter_var($input['email'], FILTER_VALIDATE_EMAIL); if (!$email) { http_response_code(400); echo json_encode(['error' => 'that email doesn\'t look right. ' . $name . ' is confused.']); exit; } $firstName = isset($input['firstName']) ? trim($input['firstName']) : ''; $lastName = isset($input['lastName']) ? trim($input['lastName']) : ''; // build attributes (only include non-empty values) $attributes = []; if ($firstName !== '') $attributes['FIRSTNAME'] = $firstName; if ($lastName !== '') $attributes['LASTNAME'] = $lastName; $payload = ['email' => $email]; if (!empty($attributes)) { $payload['attributes'] = $attributes; } $brevoApiKey = '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'; $ch = curl_init('https://api.brevo.com/v3/contacts'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'accept: application/json', 'content-type: application/json', 'api-key: ' . $brevoApiKey, ], CURLOPT_POSTFIELDS => json_encode($payload), ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $greeting = $firstName !== '' ? $firstName . ', ' : ''; $greetingLower = $firstName !== '' ? strtolower($firstName) . ' ' : 'bestie '; $successMessages = [ 'welcome ' . $greetingLower . 'to the inner circle. ' . $name . ' approves.', 'you\'re in ' . $greetingLower . '. ' . $name . ' will remember this loyalty.', 'congrats ' . $greetingLower . '. ' . $name . '\'s thoughts are now ur problem.', $greeting . $name . ' just got a little more powerful.', ]; $dupeMessages = [ $greetingLower . 'you\'re already subscribed. obsessed much? ' . $name . ' loves that.', $greetingLower . 'u already signed up. ' . $name . ' appreciates the enthusiasm tho.', $greetingLower . 'already in the fan club. ' . $name . ' sees u and respects the commitment.', ]; if ($httpCode === 201) { echo json_encode(['success' => true, 'message' => $successMessages[array_rand($successMessages)]]); } elseif ($httpCode === 204) { echo json_encode(['success' => true, 'message' => $dupeMessages[array_rand($dupeMessages)]]); } else { $body = json_decode($response, true); $isDuplicate = isset($body['code']) && $body['code'] === 'duplicate_parameter'; if ($isDuplicate) { echo json_encode(['success' => true, 'message' => $dupeMessages[array_rand($dupeMessages)]]); } else { http_response_code(500); echo json_encode(['error' => 'something went wrong. ' . $name . ' is devastated. try again.']); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | ���֧ߧ֧�ѧ�ڧ� ����ѧߧڧ��: 0 |
proxy
|
phpinfo
|
���ѧ����ۧܧ�