<?php
	session_start();
	include('config.php');
if(isset($_POST['email'])){
		
		$email = validate($conn, $_POST['email']);
		$password = validate($conn, $_POST['password']);
		$salt = $password.'bn54bnxys367jd23007';
	    $pass_by = md5($salt);
	    /*
	    if(empty($_POST['g-recaptcha-response'])){
                echo 'Captcha is required';
        }else{
          $secret_key = '6LcVt9sbAAAAAOLn5FVaV-5x6sAeRuI7E7ai6Ich';
        
          $response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret_key.'&response='.$_POST['g-recaptcha-response']);
        
          $response_data = json_decode($response);
        
            if(!$response_data->success){
               echo 'Captcha verification failed';
            }else{*/
                $qv = $conn->query("SELECT * FROM `main_reg` WHERE `email`='$email' AND `password` = '$pass_by'");
                    $r = mysqli_fetch_array($qv);
                    $active = $r['active'];
                    $e = $r['email'];
                    if(mysqli_num_rows($qv) >= 1){
                        $_SESSION['email'] = $e;
                        
                            echo 'one';
                        
                    }else{
                        echo 'two';
                        
                    }
            //}
        //}
        
        
    	


	}

	function chk_email($name, $email, $country, $conn, $lname, $password){// Check Email
		
			$c = md5($email);

			$salt = $password.'bn54bnxys367jd23007';
	    	$pass_by = md5($salt);

			$stmt = $conn->prepare("SELECT email FROM main_reg WHERE email = ?");
    		$stmt->bind_param('s', $email);
    		$stmt->execute();
    		
    		if($stmt->num_rows >= 1){
    			//echo 'email';
    			echo 'one';
    		}else{
    			

    		}
		

	}


	function reg($name, $email, $country, $conn, $lname, $password){// Registration
		
		$c = md5($email);

		$salt = $password.'bn54bnxys367jd23007';
    	$pass_by = md5($salt);

		$s = 0;
		
		$ec = $conn->query("INSERT INTO `main_reg`(`id`, `first_name`, `last_name`, `email`, `password`, `country`, `active`, `status`) VALUES (NULL,'1','2','john','4','5')");
		if($ec == true){
		    //mail_to($name, $email ,$phone, $country, $conn, $ref, $mname, $lname, $username, $password, $c);
		    echo 'three';
			//echo 'z';
		}else{
		    echo 'four';
		}
		
	}

	function validate($con, $vi){
		$var = mysqli_real_escape_string($con, $vi);
		$var_p = filter_var($var, FILTER_SANITIZE_STRING);
		return $var_p;
	}
?>