<?php
include 'anti.php';
include 'konak.php';
$ipuser = $_SERVER['REMOTE_ADDR'];
date_default_timezone_set("Asia/Jakarta");
if(isset($_POST['username']))
{
    $username = anti_injection($_POST['username']);
    $usermail = anti_injection($_POST['email']);
    $password = anti_injection($_POST['password']);
    $setthwid = anti_injection($_POST['hwid']);
    $status =  "Active"; 
    $date = date('Y-m-d');
    if ($username != "" && $usermail != "" && $password != "" && $setthwid != "")
    {
    	if($username != "" )
    	{
    		$data = mysqli_query($koneksi, "SELECT * FROM user_id WHERE username='".$username."'");
	        $user = mysqli_fetch_array($data);
	        $cek = mysqli_num_rows($data);
	         if($cek > 0)
	         {
	            echo "Username allredy registered"; 
	            return;
	         }
    	}
    	if($usermail != "" )
    	{
    		$data = mysqli_query($koneksi, "SELECT * FROM user_id WHERE email='".$usermail."'");
	        $user = mysqli_fetch_array($data);
	        $cek = mysqli_num_rows($data);
	         if($cek > 0)
	         {
	         	 echo "Email allredy registered" ;
	         	 return;
	         }
    	}
    	$sqls = "INSERT INTO user_id (last,username,email,password,hwid,status,time,expired ) VALUES ('$date','$username','$usermail','$password','$setthwid','$status','$date','$date')";
    	if(mysqli_query($koneksi, $sqls))
    	{
    	    $message = "New user registration successful\n";
    	    $message .= " ⦁ IP : " . $ipuser. "\n";
    	    $message .= " ⦁ Username : " . $username. "\n";
    	    $message .= " ⦁ Email : " . $usermail. "\n";
    	    $message .= " ⦁ Time : " . $date. "\n";
    	    telebot($message);
    		echo "done";
    	}
    	else
    	{
    		echo "gagal"; 
			echo "Could not able to execute $sql. " . mysqli_error($koneksi);
    	}
    }
    else
    {
    	echo "filed\n";
        echo "username or password not found" ;
    }
}
function telebot($message) {
$url = 'https://api.telegram.org/bot8527938197:AAEEn0qWL4g8ZIPC23RdlMW5csMVtskuRrw/sendMessage?chat_id=7066855724&text='.urlencode($message)  ;
$result = file_get_contents($url, false, $context);
if ($result === false) {

}
return $result;
}
?>