<?php

$url = 'http://api.indeed.com/ads/apisearch';

$query = $_GET['q'];
$count = 5;
$result_type = 'recent';

$params = '?';
$params .= 'publisher=2998102164832315';
$params .= '&v=2';
$params .= '&q='.urlencode($query);
$params .= '&format=json';
$params .= '&sort=date';
$params .= '&co=gb';
//$params .= '&count='.$count;
//$params .= '&result_type='.$result_type;

$requestMethod = 'GET';

//echo json_encode($params);

$response = CallAPI('GET', $url.$params);

echo $response;
//echo json_encode($params);

function CallAPI($method, $url, $data = false)
{
    $curl = curl_init();

    switch ($method)
    {
        case "POST":
            curl_setopt($curl, CURLOPT_POST, 1);

            if ($data)
                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            break;
        case "PUT":
            curl_setopt($curl, CURLOPT_PUT, 1);
            break;
        default:
            if ($data)
                $url = sprintf("%s?%s", $url, http_build_query($data));
    }

    // Optional Authentication:
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_USERPWD, "username:password");

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec($curl);

    curl_close($curl);

    return $result;
}

?>