[Código PHP] Pequeña "Api" de verificación de email

Iniciado por HckDrk, Diciembre 03, 2017, 02:06:46 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Diciembre 03, 2017, 02:06:46 PM Ultima modificación: Diciembre 03, 2017, 02:17:16 PM por HckDrk
Buenas!!

Después de muchos años de no postear algo, hoy vengo a hacerlo XD. Estaba aburrido y me puse a hacer esta pequeña api.

Este es básicamente un complemento al articulo del compañero "Arthusu" llamado  You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Básicamente se trata de una muy sencilla API Restful, en donde valida si la sintaxis del correo es correcta, si el dominio exista, si el dominio tiene registros MX y como Plus le coloque el famoso: "quisiste decir You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login".

Esta pequeña api consta de 2 archivos: el "index.php" y el "quisiste_decir.php"

En el index hace llamado del archivo "quisiste_decir.php" y hace las validaciones de sitaxis, dominio y registros MX:

Código: php

<?php
include('quisiste_decir.php');
$correo = (trim($_REQUEST['correo'])=='') ? "[email protected]" : strip_tags($_REQUEST['correo']);
$hosts=array();
$error='no';

if(filter_var($correo,FILTER_VALIDATE_EMAIL)){

$sintaxis = 'Correcta';

$dominio=explode("@",$correo);
if(checkdnsrr($dominio[1])){

$dominio_existe = 'existe';

if(getmxrr($dominio[1],$hosts)){
$mensaje = 'el correo es valido, existe el dominio, y tiene registros MX. Muy probablemente existe el correo';
$registro_mx = 'existe';
}else{

$mensaje = 'Existe el dominio, pero no tiene registros MX, por lo cual no creemos que exista el correo';
$registro_mx = 'No existe';
$error = 'si';
}
}else{

$quisiste_decir = quisiste_decir($correo);
$mensaje = 'No existe el dominio';
$dominio_existe = 'No existe';
$error = 'si';
}

}else{
$quisiste_decir = quisiste_decir($correo);
$mensaje = 'el correo no tiene la sintaxis correcta';
$sintaxis= 'Incorrecta';
$error = 'si';
}

header('Content-Type: application/json');
$json = array('error' => $error, 'quisiste_decir' => $quisiste_decir, "usuario" => $dominio[0], 'dominio' => $dominio[1], 'sisntaxis' => $sintaxis, 'dominio_existe' => $dominio_existe, 'registro_mx' => $registro_mx, 'valor_registro_mx' => $hosts, 'mensaje' => $mensaje);
echo json_encode($json,JSON_PRETTY_PRINT);

?>


y el archivo "quisiste_decir.php" que comprueba que el correo ingresado tenga coincidencias erroneas con los principales  correos gmail, hotmail, yahoo.

Código: php

<?php

function buscar_hotmail($correo){

$find_hotmail = array('jot', 'holma', 'hotmil','hotmai', 'hotmaiI');
$dominio = explode("@",$correo);

foreach($find_hotmail as $hotmail){

    if(strpos($dominio[1], $hotmail) !== false){
$retorno = $dominio[0].'@hotmail.com';
        break;
    }
   
}

if($retorno!=""){
return $retorno;
}else{
return false;
}
}

function buscar_gmail($correo){

$find_gmail = array('gmai', 'gmail', 'mail','gmal', 'gmail.co');
$dominio = explode("@",$correo);

foreach($find_gmail as $gmail){

    if(strpos($dominio[1], $gmail) !== false){
$retorno = $dominio[0].'@gmail.com';
        break;
    }
   
}

if($retorno!=""){
return $retorno;
}else{
return false;
}
}

function buscar_yahoo($correo){

$find_yahoo = array('yajoo', 'yaho', 'yhoo','ahoo', 'yahoo.co');
$dominio = explode("@",$correo);

foreach($find_yahoo as $yahoo){

    if(strpos($dominio[1], $yahoo) !== false){
$retorno = $dominio[0].'@yahoo.com';
        break;
    }
   
}

if($retorno!=""){
return $retorno;
}else{
return false;
}
}

function quisiste_decir($correo){

if(buscar_hotmail($correo)){

return buscar_hotmail($correo);

}else{

if(buscar_gmail($correo)){

return buscar_gmail($correo);

}else{

if(buscar_yahoo($correo)){

return buscar_yahoo($correo);

}else{
return false;
}

}

}

}

?>


Lo pueden probar directamente en mi dominio You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login el cual recibe 1 parametro llamado correo ya sea por post o por get.

Saludos!!!