php
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>位置取得</title> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Geolocation Sample</title> </head> <body> <script type="text/javascript"> if (navigator.geolocation) { // 現在の位置情報取得を実施 navigator.geolocation.getCurrentPosition( // 位置情報取得成功時 function (pos) { var location1 = pos.coords.latitude; var location2 = pos.coords.longitude; }, // 位置情報取得失敗時 function (pos) { var location ="<li>位置情報が取得できませんでした。</li>"; document.getElementById("location").innerHTML = location; }); } else { window.alert("本ブラウザではGeolocationが使えません"); } </script> <ul id="location"> </ul> <?php // ログ・ファイルに追記下記モードでオープン $file = @fopen('5-37.log', 'ab') or die('ファイルを開けませんでした!'); // ファイルのロック flock($file, LOCK_EX); // ファイルの書き込み fwrite($file, implode("\t", $url) ."\n"); // ロックの解除 flock($file, LOCK_UN); // ファイルを閉じる fclose($file); print 'アクセスログを記録しました。'; ?> </body>
//////////////////////////////////
追記
//////////////////////////////////
色々調べた結果、index.php(内のJavascript)でlocation1
とlocation2
の値を取得し、send.phpで受け取ったlocation1
とlocation2
を表示&ファイル書き込みを行いたいです。表示&書き込みのやり方は分かるんですが、データの渡し方がわかりません。
index.phpのlocation1
とlocation2
をsend.phpへ渡す方法を教えて下さい。
index.php
php
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>位置取得</title> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Geolocation Sample</title> </head> <body> <?php $data[0]; ?> <script type="text/javascript"> if (navigator.geolocation) { // 現在の位置情報取得を実施 navigator.geolocation.getCurrentPosition( // 位置情報取得成功時 function (pos) { var location ="<li>"+"緯度:" + pos.coords.latitude + "</li>"; location += "<li>"+"経度:" + pos.coords.longitude + "</li>"; document.getElementById("location").innerHTML = location; }, // 位置情報取得失敗時 function (pos) { var location ="<li>位置情報が取得できませんでした。</li>"; document.getElementById("location").innerHTML = location; }); } else { window.alert("本ブラウザではGeolocationが使えません"); } </script> <ul id="location"> </ul> </body>
send.php
php
<?php $num = isset($_POST['hidden_input']) ? $_POST['hidden_input'] : null; // ログ・ファイルに追記下記モードでオープン $file = @fopen('5-37.log', 'ab') or die('ファイルを開けませんでした!'); // ファイルのロック flock($file, LOCK_EX); // ファイルの書き込み fwrite($file, implode("\t", $url) ."\n"); // ロックの解除 flock($file, LOCK_UN); // ファイルを閉じる fclose($file); print 'アクセスログを記録しました。'; ?>
まだ回答がついていません
会員登録して回答してみよう