'error', 'message'=>'CRITICAL: PHP cURL extension missing. Contact Hosting.']); exit(); } if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit(); } if ($_SERVER['REQUEST_METHOD'] !== 'POST') { echo json_encode(['status'=>'error', 'message'=>'POST Only']); exit(); } // Get Input $input = json_decode(file_get_contents('php://input'), true); if (json_last_error() !== JSON_ERROR_NONE) { echo json_encode(['status'=>'error', 'message'=>'Invalid JSON Input']); exit(); } $url = isset($input['url']) ? trim($input['url']) : ''; $proxyConfig = isset($input['proxy']) ? $input['proxy'] : null; $rawCookie = isset($input['cookie']) ? $input['cookie'] : null; // --- SMART COOKIE CLEANER --- $cookie = ''; if (!empty($rawCookie)) { // 1. Ensure it's a string if (is_array($rawCookie)) { // If frontend accidentally sent an array, take the first value $rawCookie = isset($rawCookie[0]) ? $rawCookie[0] : ''; } $cookie = trim((string)$rawCookie); // 2. Remove "li_at=" if user pasted it $cookie = str_ireplace('li_at=', '', $cookie); // 3. Remove surrounding quotes and spaces $cookie = trim($cookie, '"\' '); // 4. Force quote wrapping for safety (LinkedIn cookies often have special chars like &) // Only wrap if not empty if (!empty($cookie)) { $cookie = 'li_at="' . $cookie . '"'; } } if (empty($url)) { echo json_encode(['status'=>'error', 'message'=>'No URL']); exit(); } // --- TEST ENDPOINT --- if ($url === 'https://linkedin.com/in/test') { $msg = 'PHP Connected'; if (!empty($cookie)) { // Try to access Feed to verify cookie $testStatus = checkLinkedIn('https://www.linkedin.com/feed/', $proxyConfig, $cookie); if (strpos($testStatus['message'], 'Active') !== false || strpos($testStatus['message'], 'Feed') !== false) { $msg = 'Cookie Working (Session Active) ✅'; } else { // Debug info: Show where it redirected $msg = 'Cookie Failed ❌ (' . $testStatus['message'] . ')'; } } else { $msg .= ' (No Cookie Provided)'; } echo json_encode(['status'=>'valid', 'message'=>$msg]); exit(); } function checkLinkedIn($url, $proxyConfig, $cookie) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 5); // Limit redirects curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Enable Cookie Engine (Critical for session handling) curl_setopt($ch, CURLOPT_COOKIEFILE, ""); // Accept Encoding (Gzip) - Makes it look more like a browser curl_setopt($ch, CURLOPT_ENCODING, ""); // Real Browser Headers $headers = [ 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8', 'Accept-Language: en-US,en;q=0.9', 'Upgrade-Insecure-Requests: 1', 'Sec-Ch-Ua: "Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"', 'Sec-Ch-Ua-Mobile: ?0', 'Sec-Ch-Ua-Platform: "Windows"', 'Sec-Fetch-Dest: document', 'Sec-Fetch-Mode: navigate', 'Sec-Fetch-Site: none', 'Sec-Fetch-User: ?1', 'Connection: keep-alive' ]; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // --- SET COOKIE --- if (!empty($cookie)) { curl_setopt($ch, CURLOPT_COOKIE, $cookie); } // --- PROXY SETUP --- if ($proxyConfig && !empty($proxyConfig['host'])) { $proxy = $proxyConfig['host'] . ':' . $proxyConfig['port']; curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME); if (!empty($proxyConfig['user'])) { curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyConfig['user'] . ':' . $proxyConfig['pass']); } } $html = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $finalUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); $curlError = curl_error($ch); curl_close($ch); if ($curlError) { return ['status' => 'error', 'message' => 'cURL Error: ' . $curlError]; } // --- ANALYSIS --- // 1. Check for Feed (Test Mode / Self Check) if ($url === 'https://www.linkedin.com/feed/') { // Check for feed specific indicators if ($httpCode == 200 && ( strpos($finalUrl, '/feed') !== false || strpos($html, 'feed-identity-module') !== false || strpos($html, 'share-box-feed-entry') !== false )) { return ['status' => 'valid', 'message' => 'Active (Feed Access)']; } // If redirected to login if (strpos($finalUrl, 'login') !== false || strpos($finalUrl, 'uas/auth') !== false) { return ['status' => 'invalid', 'message' => 'Login Redirect']; } return ['status' => 'invalid', 'message' => 'Login Failed (Code: '.$httpCode.')']; } // 2. LOGGED IN MODE (Checking Profiles with Cookie) if (!empty($cookie)) { if ($httpCode == 200) { // Check Title if (preg_match('/