Problem With Email Checker Function in PHP [closed]

3 weeks ago 34
ARTICLE AD BOX

Currently, I have a problem with this function. I want a function that checks if an email address is available or not. I tried to add another method for checking, but it's not working. If anyone has another method to check if an email is available or not, please let me know.

Here is the code I wrote, but I am curious as to why it isn't working and how can I fix the issue

function checkGmail($mail){ echo "[Gmail] Testing if exists: $mail\n"; flush(); $ch = curl_init(); // First: Get initial page to extract XSRF token curl_setopt($ch, CURLOPT_URL, 'https://accounts.google.com/signin/v2/identifier'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'); curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/gmail_cookies.txt'); $res = curl_exec($ch); $err = curl_error($ch); curl_close($ch); if($err){ echo "[Gmail] Network error, allowing\n"; flush(); return true; } // Extract XSRF token if(preg_match('/"_XSRF_TOKEN"\s*,\s*"([^"]+)"/', $res, $m)){ $xsrf = $m[1]; } else if(preg_match('/name="_xsrf_token"\s+value="([^"]+)"/', $res, $m)){ $xsrf = $m[1]; } else { $xsrf = ''; } // Now check if email exists using the identifier endpoint $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://accounts.google.com/signin/v2/identifier?service=accountsettings&continue=https://myaccount.google.com&osid=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/x-www-form-urlencoded', 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' ]); curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/gmail_cookies.txt'); curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/gmail_cookies.txt'); $postData = 'identifier='.$mail.'&_xsrf_token='.$xsrf; curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); $res2 = curl_exec($ch); $http = curl_getinfo($ch, CURLINFO_HTTP_CODE); $err2 = curl_error($ch); curl_close($ch); // Analyze response if($err2){ echo "[Gmail] Error, allowing: $err2\n"; flush(); return true; } // Check response for existence indicators if(stripos($res2, 'Could not find your Google Account') !== false || stripos($res2, 'account does not exist') !== false || stripos($res2, 'no account found') !== false){ echo "[Gmail] ✓ Available (not found)\n"; flush(); return true; } if(stripos($res2, 'password') !== false || stripos($res2, 'enter your password') !== false || stripos($res2, 'verify it\'s you') !== false){ echo "[Gmail] ✗ Taken (account found)\n"; flush(); return false; } // If we get HTML form asking for password = account exists if(stripos($res2, '<input') !== false && stripos($res2, 'password') !== false){ echo "[Gmail] ✗ Taken (password form shown)\n"; flush(); return false; } echo "[Gmail] Unclear response, assuming taken\n"; flush(); return false; }
Read Entire Article