<?php
    header('Access-Control-Allow-Origin: *'); 
    header("Access-Control-Allow-Credentials: true");
    header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
    header('Access-Control-Max-Age: 1000');
    header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token , Authorization');
    $suNumber = $_REQUEST['suNumber'];
    $dob = $_REQUEST['dobYyyymmdd'];
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => "https://serviceproxy.sun.ac.za/sunstudent-api/info/student?suNumber=".$suNumber."&dobYyyymmdd=".$dob,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "GET",
        CURLOPT_USERPWD => "sunstudent:vBBVgjaFz357k8Wj",
        CURLOPT_HTTPHEADER => array(
            "cache-control: no-cache",
            "content-type: application/json"
        ),
));
$response = curl_exec($curl);
$responseDecode = json_decode($response, true);
if(isset($responseDecode['email']) && $responseDecode['email'])
{
    $response = array('email' => $responseDecode['email']);
    $response = json_encode($response);
}
echo $response;