<?php
require_once ("varables.php");

$myJSON['message'] = "خطای اطلاعات";
$myJSON['mmm'] = array();
if(isset($_POST["an1d"]) && isset($_POST["nekot"])&& isset($_POST["pa333"]) )
{

	$toke =  $_POST["nekot"];
	$user_id = $_POST["an1d"];
	$pas = $_POST["pa333"];

    $connect = @mysqli_connect($hostname,$username,$password,$database);
    if($connect)
    {
        @mysqli_query($connect,"SET CHARACTER SET utf8;");
        $query_token = "SELECT id FROM ".$tbl_sessions." WHERE token = '".$toke."' AND uid ='".$user_id."' AND type ='V' LIMIT 1";
				$tokres=@mysqli_query($connect,$query_token);
        if (!$tokres) {
            $myJSON['message']= "خطای پایگاه داده" ;

        }
		else{
			$countoft = 0;
            while($rowt = @mysqli_fetch_assoc($tokres)){
				array_push($myJSON['mmm'], $rowt);
                $countoft++;
			}
			if($countoft == 0){
				$myJSON['message']= "خطای اعتبارسنجی...!" ;
			}
			else{
								$update_q = "UPDATE ".$tbl_visitors." SET pass = '".$pas."' WHERE id = '".$user_id."'";
								$updateres=@mysqli_query($connect,$update_q);
								if(!$updateres)
				            	$myJSON['message']= "خطای پایگاه داده";
								else {
									$myJSON['message']= "200";
								}
						}

					}
				}



	 else
		 $myJSON['message']="خطای اتصال";
}
    echo json_encode($myJSON);

?>
