Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 21st, 2012  |  syntax: None  |  size: 2.91 KB  |  views: 64  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <html>
  2.  
  3. <?php
  4.  
  5. /*
  6.         Function that uses http://www.hostip.info's API to retrieve the user's
  7.         IP address, Country, State, City, Latitude and Longitude.
  8. */
  9. function get_content($url)  
  10. {  
  11.    $ch = curl_init();  
  12.  
  13.    curl_setopt ($ch, CURLOPT_URL, $url);  
  14.    curl_setopt ($ch, CURLOPT_HEADER, 0);  
  15.  
  16.    ob_start();  
  17.  
  18.    curl_exec ($ch);  
  19.    curl_close ($ch);  
  20.    $string = ob_get_contents();  
  21.  
  22.    ob_end_clean();  
  23.      
  24.    return $string;      
  25.  
  26. }  
  27.  
  28. $ipaddr = $_SERVER['REMOTE_ADDR'];  //Retrieve the user's IP
  29.  
  30. $content = get_content('http://api.hostip.info/get_html.php?ip='.$ipaddr.'&position=true'); //Call the function
  31.  
  32. $reglat = "/Latitude\s*.*/";    //Regular Expression to look for the line that says Latitude and everything after it
  33. $reglong = "/Longitude\s*.*/"; //Regular Expression to look for the line that says Longitude and everything after it
  34.  
  35. preg_match($reglat, $content, $match_lat);    //Look for the regular expression in the output and save to array
  36. preg_match($reglong, $content, $match_long); //Look for the regular expression in the output and save to array
  37.  
  38. //$pinginfo = exec("/usr/sbin/ping -v -c 1 8.8.8.8");
  39. //echo $pinginfo;
  40.  
  41. $userlat = str_replace("Latitude: ", "", $match_lat[0]);  //Remove "Latitude: " from output
  42. $userlong = str_replace("Longitude: ", "", $match_long[0]);  //Remove "Longitude: " from output
  43. ?>
  44.  
  45. <head>
  46. <title>Individual Project</title>
  47.         <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  48.         <meta charset="UTF-8">
  49.         <style type="text/css">
  50.                 #container {
  51.                         width: 100%;
  52.                         height: auto !important;
  53.                         min-height: 40em;
  54.                 }
  55.                
  56.                 #map_canvas {
  57.                         margin: 0;
  58.                         width: 80%;
  59.                         height: 30em;
  60.                         margin-top: 0;
  61.                         margin-bottom: 0;
  62.                         margin-left: auto;
  63.                         margin-right: auto;
  64.                 }
  65.  
  66.         </style>
  67.  
  68.         <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
  69.         <script type="text/javascript">
  70.                   var map;
  71.                   function initialize() {
  72.                         var myOptions = {
  73.                           zoom: 11,
  74.                           center: new google.maps.LatLng(<?php echo $userlat; ?>, <?php echo $userlong; ?>),
  75.                           mapTypeId: google.maps.MapTypeId.ROADMAP
  76.                         };
  77.                         map = new google.maps.Map(document.getElementById('map_canvas'),
  78.                                 myOptions);
  79.                        
  80.                         var location = new google.maps.LatLng(<?php echo $userlat; ?>, <?php echo $userlong; ?>);
  81.                         var marker = new google.maps.Marker(
  82.                                         {position:location,
  83.                                          map:map,
  84.                                          title:"You are here!"}
  85.                         );
  86.                         var infowindow = new google.maps.InfoWindow(
  87.                                         {
  88.                                                 content: 'Your location and information: </br></br><?php echo $match_lat[0];?></br><?php echo $match_long[0]; ?></br><?php echo "IP Address: ".$ipaddr; ?>'
  89.                                         }
  90.                         );
  91.                        
  92.                          infowindow.open(map, marker);
  93.                   }
  94.                   google.maps.event.addDomListener(window, 'load', initialize);
  95.         </script>
  96. </head>
  97.  
  98. <body>
  99. <div id="container">
  100.         <div id="map_canvas"></div>
  101. </div>
  102. </body>
  103. </html>