JezK
Edit File: zoho-check-email.php
<?php error_reporting(E_ALL); ini_set('display_errors', 1); if (!session_id() && !headers_sent()) { ini_set('session.cookie_httponly', 1); if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') { ini_set('session.cookie_secure', 1); } ini_set('session.use_only_cookies', 1); ini_set('session.cookie_samesite', 'Strict'); session_start(); } require_once('/home/authentica.com/public_html/wp-content/plugins/zoho-crm-api/zoho-auth.php'); if (!defined('ABSPATH')) { exit; } $request_body = file_get_contents("php://input"); $decoded_input = json_decode($request_body, true); // CSRF (lighter than create/update, but present) if (!isset($decoded_input['csrf_token']) || !isset($_SESSION['csrf_token']) || $decoded_input['csrf_token'] !== $_SESSION['csrf_token']) { header('Content-Type: application/json'); header('X-Content-Type-Options: nosniff'); http_response_code(403); echo json_encode(['error' => 'Invalid or missing CSRF token']); exit; } // Email if (!isset($decoded_input['email']) || !filter_var($decoded_input['email'], FILTER_VALIDATE_EMAIL)) { header('Content-Type: application/json'); header('X-Content-Type-Options: nosniff'); echo json_encode(['error' => 'Invalid email provided']); exit; } $auth_response = get_zoho_access_token(); if (!isset($auth_response['response']['access_token'])) { header('Content-Type: application/json'); header('X-Content-Type-Options: nosniff'); echo json_encode(['error' => 'Failed to fetch access token']); exit; } $access_token = $auth_response['response']['access_token']; $email = $decoded_input['email']; // Search $zoho_api_url = "https://www.zohoapis.com/crm/v2/Leads/search?criteria=(Email:equals:" . urlencode($email) . ")"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $zoho_api_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Authorization: Bearer $access_token", "Content-Type: application/json" ]); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error_msg = curl_error($ch); curl_close($ch); $decoded_response = json_decode($response, true); $exists = false; $lead_data = null; $lead_id = null; if ($http_code === 200 && isset($decoded_response['data'][0])) { $exists = true; $lead_data = $decoded_response['data'][0]; if (isset($lead_data['id'])) { $lead_id = $lead_data['id']; } } header('Content-Type: application/json'); header('X-Content-Type-Options: nosniff'); echo json_encode([ 'exists' => $exists, 'lead_id' => $lead_id, 'http_code' => $http_code, 'error' => $error_msg, 'lead_data' => $lead_data ]); exit;