I'm trying to make simply trip calculator, and i am here and don't know what to do next, also it seemed to work, but it doesn't.
So up there is a question, becouse this code should give me a json file, looking for some advice guys :3
<form action="#" method="get">
<input type="text" name="origin" value="" placeholder="Origin">
<input type="text" name="destination" value="" placeholder="Destination">
<input type="submit" name="submit" value="wyslij">
</form>
<?php
//https://maps.googleapis.com/maps/api/directions/json?origin=Disneyland&destination=Universal+Studios+Hollywood4&key=YOUR_API_KEY
define("YOUR_API_KEY","AIzaSyDqFsGPY9bSMtjh8S3oYAr1o0cPkBgCV1g");
$origin = $_GET["origin"];
$destination = $_GET["destination"];
if(isset($origin) && isset($destination) && !empty($origin) && !empty($destination)){
$url = "https://maps.googleapis.com/maps/api/directions/json?origin=".$origin."&destination=".$destination."&key=".YOUR_API_KEY;
//echo $url;
if(file_put_contents($url,true)) echo '<p>DZIALA</p>';
$str = file_put_contents($url,true);
$json = json_decode($str, true);
echo '<pre>' . print_r($json, true) . '</pre>';
}
else{
echo "sth";
}
?>