简体   繁体   中英

Sending IP Data to Server in Javascript

So I am making a web page, and one of the functions I want is to be able to store global IPs into a text file. I am a NOOB as far as this web development is concerned (Hardware dude).

So far I have on the client side-

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>IP Grab</title> <meta name="description" content="A privileged app stub"> <meta name="viewport" content="width=device-width"> <link rel="stylesheet" href="css/app.css"> <script type="text/javascript" src="js/app.js" defer></script> <link rel="prefetch" type="application/l10n" href="data/locales.ini" /> <script type="text/javascript" src="js/libs/l10n.js" defer></script> </head> <body> <!-- Find Global IP Address --> <script type="application/javascript"> function getIP(json) { document.write("My public IP address is: ", json.ip); } </script> <script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script> <!-- Send Data to Server --> <script> jQuery.ajax({ method: "POST", url: "get.php", data: json.ip }) </script> </body> </html> 

On the server side-

 <?php data = $_POST['text']; list($type, $data) = explode(';', $data); list(, $data) = explode(',', $data); $data = base64_decode($data); file_put_contents('ips.txt', $data); > 

I KNOW the php portion is VERY wrong... can someone point me in the right direction? I'm having a heard time finding a good tut.

Thanks

Getting the client ip is easy in PHP .

$your_ip = $_SERVER['REMOTE_ADDR'];  

for more info you can visit PHP's official website http://php.net/manual/en/reserved.variables.server.php

on a side note , you should read about http request and response cycle .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM