Skip to content

Instantly share code, notes, and snippets.

@laerciobernardo
Created January 2, 2019 22:29
Show Gist options
  • Save laerciobernardo/7a70c36c4e64309abb4717251f53fc14 to your computer and use it in GitHub Desktop.
Save laerciobernardo/7a70c36c4e64309abb4717251f53fc14 to your computer and use it in GitHub Desktop.
Test get ip and store on firebase
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="https://www.gstatic.com/firebasejs/5.7.2/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyBLKaabAI6odL5DNyu3c8I1uNfFzMs0do4",
authDomain: "iptest-e9456.firebaseapp.com",
databaseURL: "https://iptest-e9456.firebaseio.com",
projectId: "iptest-e9456",
storageBucket: "iptest-e9456.appspot.com",
messagingSenderId: "191011807786"
};
firebase.initializeApp(config);
function writeIPData(ip) {
console.log('gravando o ip')
let ref = firebase.database().ref('ip/')
console.log(ref)
}
function getip(json) {
alert(json.ip); // alerts the ip address
writeIPData(json.ip);
}
</script>
<script type="application/javascript" src="https://jsonip.com?callback=getip"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment