<?php
//ini_set("allow_url_fopen", 1);
//ini_set("allow_url_include", 1);

//$data = file_get_contents('http://www.google.com');
//$data = file('http://181.49.188.18/Saf/rest_usuarios/getInstructoresActivos.json');

//$data = file_get_contents('http://181.49.188.18/Saf/rest_usuarios/getInstructoresActivos.json');
$data = getRemoteFile('http://181.49.188.18/Saf/rest_horarios/obtenerAmbientes.json');
print_r($data);

function getRemoteFile($url, $timeout = 1000) {
  print_r("Entreeeeeeeee.......");	
  $ch = curl_init();
  curl_setopt ($ch, CURLOPT_URL, $url);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $file_contents = curl_exec($ch);
  curl_close($ch);
  return ($file_contents) ? $file_contents : FALSE;
}


/* 
if (! function_exists ( 'curl_version' )) {
    exit ( "Enable cURL in PHP" );
}

$ch = curl_init ();
$timeout = 0; // 100; // set to zero for no timeout
$myHITurl = "http://www.google.com";
//$myHITurl = "http://181.49.188.18/Saf/rest_usuarios/getInstructoresActivos.json";
//$myHITurl = "http://181.49.188.18/Saf";
curl_setopt ( $ch, CURLOPT_URL, $myHITurl );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
$file_contents = curl_exec ( $ch );
if (curl_errno ( $ch )) {
    echo curl_error ( $ch );
    curl_close ( $ch );
    exit ();
}
curl_close ( $ch );

// dump output of api if you want during test
echo "$file_contents";
*/

/* 
$urlEncoded='Content-Type: application/x-www-form-urlencoded';
$myHITurl = "http://181.49.188.18/Saf/rest_horarios/obtenerCursosActivos.json";
//$myHITurl = "http://www.google.com";

$a=curl($myHITurl ,'GET','',"",array($urlEncoded));

print_r($a); 

function curl($url,$method,$cookie,$data,$header) {
//public static function curl($task,$method,$cookie,$data,$header) {
	
	$res=new stdClass();
	$res->responseCode='';
	$res->error='';
	$header[]="Cookie: ".$cookie;
	
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	//curl_setopt($ch, CURLOPT_URL, self::$host.$task);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
	
	if($method=='POST' || $method=='PUT' || $method=='DELETE') {
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	}
	
	curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
	$data=curl_exec($ch);
	$size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
	
	if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', substr($data, 0, $size), $c) == 1) 
	{	
		$cookie = $c[1];
		print_r($cookie);
	}
	$res->response = substr($data, $size);
    	
	if(!curl_errno($ch)) {
		$res->responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	}
	else {
		$res->responseCode=400;
		$res->error= curl_error($ch);
	}
	
	curl_close($ch);
	return $res;
}

*/




?>