Передача переменной из JS в PHP
fetch('https://ipwho.is/?format=json')
.then(d => d.json())
.then(d => document.querySelector('#ip').innerHTML = d.ip);
<div id="ip"></div> и есть часть php, которая записывает в лог
$rot=$_SERVER['HTTP_REFERER'];
$date=date('d.m.Y|G:i:s');
$log=fopen("info.txt","a+");
fwrite($log,"|$rot|$date|\n");
fclose($log);
как передать значение переменной #ip из js, в php для записи в лог? или передать содержимое внутри <div id="ip"></div> в php... |
fetch('https://ipwho.is/?format=json')
.then(d => d.json())
.then(res => {
return fetch('/<your-php-script-address-here>', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(res),
});
});
PHP: $receivedIP = $_POST['ip'] ?? null; |
fetch('https://ipwho.is/?format=json')
.then(d => d.json())
.then(res => {
return fetch('ind2.php', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(res),
});
});
<div id="ip"></div> ind2.php
$receivedIP = $_POST['ip'] ?? null;
$rot=$_SERVER['HTTP_REFERER'];
$date=date('d.m.Y|G:i:s');
$log=fopen("info.txt","a+");
fwrite($log,"|$rot|$date|$receivedIP|\n");
fclose($log);
примерно так? или что-то еще нужно добавить, чтоб работало? |
Grasss, примерно так
|
| Часовой пояс GMT +3, время: 13:34. |