(F)write in a html file to the visitor's geo-coordinates using a post inside a get
<p>I'm working with the coordinates. I don't want to use a GeoIP database. So I tried first to get the coordinates, then send them with a post to a php file which write them in an html file.
This is the index.html code:</p>

<pre><code>&lt;p&gt; Hello. &lt;/p&gt;

&lt;script type="text/javascript"&gt;

$.get("http://ipinfo.io", function (response) {
var ip = response.ip;
var city = response.city;
var region = response.region;
var details = JSON.stringify(response, null, 4); 

  $.ajax({
    type: "POST",
    url: 'write.php', 
    data: '&amp;ip='+ ip + '&amp;city=' + city +  '&amp;region=' + region +  '&amp;details=' + details,
    success: function (data) {   
      alert("Sent!");
    },
    error: function(jqXHR, text, error){ 
       alert("Error: not sent.");       
      }
  }); 

}, "jsonp");
</code></pre>

<p></p>

<p>this is the write.php code:</p>

<pre><code>&lt;?php 

    $ip = $_POST['ip'];
    $city = $_POST['city'];
    $region = $_POST['region'];
    $details = $_POST['details']; 

$fh = fopen('lol.html', 'a') or die("can't open file");

fwrite($fh,'IP: $ip ;');
fwrite($fh,'Details: $details'); 

fclose($fh);

echo "Created";
?&gt; 
</code></pre>

<p>If I host and open index.html it alert "Sent!". But then, when I open lol.html I see the string: <code>IP: $ip ;Details: $details</code></p>

<p>Why? What am I doing wrong? </p>