I got a question thrue PM for the code of my traffic php page, here it goes, so someone else can also use it:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Traffic information</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta name="HandheldFriendly" content="true" /><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="viewport" content="width=device-width,height=device-height,user-scalable=yes,minimal-ui" />
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="refresh" content="30;traffic.php" >
</head><body>
<?php //error_reporting(E_ALL);ini_set("display_errors", "on");
if (ob_get_level() == 0) ob_start();
function traffic($startlat, $startlon, $endlat, $endlon) {
GLOBAL $traffic;
$traffic=file_get_contents('https://www.waze.com/row-RoutingManager/routingRequest?from=x%3A'.$startlon.'+y%3A'.$startlat.'&to=x%3A'.$endlon.'+y%3A'.$endlat.'&at=0&returnJSON=true&timeout=60000&nPaths=1&clientVersion=4.0.0');
$traffic=json_decode($traffic,true);
$tijd=0;$lengte=0;
if(isset($traffic['response']['results'])) {
foreach($traffic['response']['results'] as $street) {
$tijd = $tijd + $street['crossTime'];
}
return $tijd;
}
}
echo '<a href="javascript:location.reload();" style="padding:12px 42px;font-size:20px;font-weight:500;">Verkeersinfo van '.strftime("%k:%M:%S",time()).'</a>';
ob_flush();flush();
echo '<table cellpadding="3px" cellspacing="0px" border="1px" bordercolor="#BBB" bordercolorlight="#BBB" bordercolordark="#BBB"><tr><td width="110px">Van</td><td width="110px">Naar</td><td width="75px" align="center">Tijd</td><td width="75px">Vertraging</td><tr>';
$tijd = traffic(50.892565,3.114135,50.877122,4.164326);
if($tijd>0) {echo '<tr><td>Home</td><td>Work</td><td align="center">'.strftime("%k:%M:%S",$tijd-3600).'</td><td align="center">';if($tijd>3600) echo strftime("%k:%M:%S",$tijd-3600-3600); echo '</td></tr>';} else echo '<tr><td colspan="4">error</td></tr>';
ob_flush();flush();
$tijd = traffic(50.877122,4.164326,50.892565,3.114135);
if($tijd>0) {echo '<tr><td>Work</td><td>Home</td><td align="center">'.strftime("%k:%M:%S",$tijd-3600).'</td><td align="center">';if($tijd>3600) echo strftime("%k:%M:%S",$tijd-3600-3600); echo '</td></tr>';} else echo '<tr><td colspan="4">error</td></tr>';
ob_flush();flush();
$tijd = traffic(50.892565,3.114135,50.928279,5.392641);
if($tijd>0) {echo '<tr><td>Home</td><td>Hasselt</td><td align="center">'.strftime("%k:%M:%S",$tijd-3600).'</td><td align="center">';if($tijd>7200) echo strftime("%k:%M:%S",$tijd-3600-7200); echo '</td></tr>';} else echo '<tr><td colspan="4">error</td></tr>';
ob_flush();flush();
$tijd = traffic(50.928279,5.392641,50.892565,3.114135);
if($tijd>0) {echo '<tr><td>Hasselt</td><td>Home</td><td align="center">'.strftime("%k:%M:%S",$tijd-3600).'</td><td align="center">';if($tijd>7200) echo strftime("%k:%M:%S",$tijd-3600-7200); echo '</td></tr>';} else echo '<tr><td colspan="4">error</td></tr>';
ob_flush();flush();
$tijd = traffic(50.892565,3.114135,51.033714,3.701498);
if($tijd>0) {echo '<tr><td>Home</td><td>Gent</td><td align="center">'.strftime("%k:%M:%S",$tijd-3600).'</td><td align="center">';if($tijd>2656) echo strftime("%k:%M:%S",$tijd-3600-2656); echo '</td></tr>';} else echo '<tr><td colspan="4">error</td></tr>';
ob_flush();flush();
$tijd = traffic(51.033714,3.701498,50.892565,3.114135);
if($tijd>0) {echo '<tr><td>Gent</td><td>Home</td><td align="center">'.strftime("%k:%M:%S",$tijd-3600).'</td><td align="center">';if($tijd>2656) echo strftime("%k:%M:%S",$tijd-3600-2656); echo '</td></tr>';} else echo '<tr><td colspan="4">error</td></tr>';
ob_flush();flush();
$tijd = traffic(50.892565,3.114135,51.208264,4.441884);
if($tijd>0) {echo '<tr><td>Home</td><td>Antwerpen</td><td align="center">'.strftime("%k:%M:%S",$tijd-3600).'</td><td align="center">';if($tijd>4285) echo strftime("%k:%M:%S",$tijd-3600-4285); echo '</td></tr>';} else echo '<tr><td colspan="4">error</td></tr>';
ob_flush();flush();
$tijd = traffic(51.208264,4.441884,50.892565,3.114135);
if($tijd>0) {echo '<tr><td>Antwerpen</td><td>Home</td><td align="center">'.strftime("%k:%M:%S",$tijd-3600).'</td><td align="center">';if($tijd>4285) echo strftime("%k:%M:%S",$tijd-3600-4285); echo '</td></tr>';} else echo '<tr><td colspan="4">error</td></tr>';
ob_flush();flush();
echo '</table>';
ob_end_flush();
?>
</body></html>