<?php
	session_start();
	if(!isset($_REQUEST['memberID']) || empty($_REQUEST['memberID'])){
		$validErr = "Please Enter Member ID";
	} else if(!isset($_REQUEST['password']) || empty($_REQUEST['password'])){
		$validErr = "Please Enter Password";
	} 

	if(isset($validErr) )
	{
		$result['status'] = 0;
		$result['message'] = $validErr;
		echo json_encode($result);exit;
	}

	$url = "http://localhost/MyBooster/API/API_login.php/API_login.php";

	$params['memberID'] = $_REQUEST['memberID'];
	$params['password'] = $_REQUEST['password'];
	
	//$data_string = http_build_query($params);

    /*$ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $output = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);*/

	$ch = curl_init();
	curl_setopt( $ch, CURLOPT_URL, $url);
	curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt( $ch, CURLOPT_VERBOSE, true );
	curl_setopt( $ch, CURLOPT_ENCODING, '' );
	curl_setopt( $ch, CURLOPT_CUSTOMREQUEST,'POST');
	curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($params));
	curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
	   'Content-Type: application/json'
	) );

    $output = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    $result = json_decode($output,true);
   // print_r( $result );exit;
    if($result['success']==1):

	    $_SESSION['email_address'] = $result['email_address'];
	    $_SESSION['mobile_number'] = $result['mobile_number'];
	    $_SESSION['refer_id'] = $result['refer_id'];
	    $_SESSION['user_id'] = $result['user_id'];
	    $_SESSION['username'] = $result['username'];


	else:
		
		session_unset();
		session_destroy();

	endif;

    print $output;

	?>